Skip to content
forked from PRQL/prqlc-r

R Bindings for the prql-compiler Rust Library

License

Notifications You must be signed in to change notification settings

sorhawell/prqlr

 
 

Repository files navigation

prqlr

prqlr status badge CRAN status

R bindings for the prql-compiler Rust library, powered by the extendr framework.

Installation

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.

Example

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() |>
  tidyquery::show_dplyr()
#> mtcars %>%
#>   filter(cyl > 6) %>%
#>   select(cyl, mpg)

Development

Use the rextendr::document() function to generate R source code from Rust source code in the src directory.

About

R Bindings for the prql-compiler Rust Library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • R 70.4%
  • Rust 27.1%
  • C 2.5%