R bindings for the
prql-compiler
Rust library, powered by the extendr
framework.
Requires R 4.2.0 or later.
This package can be installed from CRAN or R-universe. If available, a binary package will be installed.
# Install from CRAN
install.packages("prqlr")
# Install from R-universe
install.packages("prqlr", repos = "https://eitsupi.r-universe.dev")
For source installation, the Rust toolchain must be configured. Please check the https://github.com/r-rust/hellorust repository.
library(prqlr)
"from mtcars | filter cyl > 6 | select [cyl, mpg]" |>
prql_compile() |>
cat()
#> SELECT
#> cyl,
#> mpg
#> FROM
#> mtcars
#> WHERE
#> cyl > 6
#>
#> -- Generated by PRQL compiler version 0.4.0 (https://prql-lang.org)
PRQL’s pipelines can be joined by the newline character
(\n
), or actual newlines in addition to |
.
"from mtcars \n filter cyl > 6 \n select [cyl, mpg]" |>
prql_compile() |>
cat()
#> SELECT
#> cyl,
#> mpg
#> FROM
#> mtcars
#> WHERE
#> cyl > 6
#>
#> -- Generated by PRQL compiler version 0.4.0 (https://prql-lang.org)
"from mtcars
filter cyl > 6
select [cyl, mpg]" |>
prql_compile() |>
cat()
#> SELECT
#> cyl,
#> mpg
#> FROM
#> mtcars
#> WHERE
#> cyl > 6
#>
#> -- Generated by PRQL compiler version 0.4.0 (https://prql-lang.org)
Thanks to the {tidyquery}
package, we can even convert a
PRQL query to a SQL query and then to a {dplyr}
query!
"from mtcars
filter cyl > 6
select [cyl, mpg]" |>
prql_compile() |>
::show_dplyr()
tidyquery#> mtcars %>%
#> filter(cyl > 6) %>%
#> select(cyl, mpg)
Use the rextendr::document()
function to generate R
source code from Rust source code in the src
directory.