An open API service indexing awesome lists of open source software.

https://github.com/prql/prqlc-r

R Bindings for prqlc
https://github.com/prql/prqlc-r

prql r rust sql

Last synced: 9 months ago
JSON representation

R Bindings for prqlc

Awesome Lists containing this project

README

          

---
output:
github_document:
html_preview: false
---

```{r}
#| include: false

knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# prqlr

[![prqlr status badge](https://prql.r-universe.dev/badges/prqlr)](https://prql.r-universe.dev)
[![CRAN status](https://www.r-pkg.org/badges/version/prqlr)](https://CRAN.R-project.org/package=prqlr)
[![R-multiverse status](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fcommunity.r-multiverse.org%2Fapi%2Fpackages%2Fprqlr&query=%24.Version&label=r-multiverse)](https://community.r-multiverse.org/prqlr)

R bindings for [the `prqlc` Rust library](https://github.com/prql/prql),
powered by [`savvy`](https://github.com/yutannihilation/savvy).

This version supports PRQL `r prqlr::prql_version()`.

## Installation

Requires R 4.2.0 or later.

This latest release version of this package can be installed from CRAN or [R-multiverse](https://r-multiverse.org).
If available, a binary package will be installed.

```r
# Install from CRAN
install.packages("prqlr")
```

```r
# Install from the R-multiverse Community Repository
install.packages("prqlr", repos = "https://community.r-multiverse.org")
```

Development version of this package can be installed from PRQL's
[R-universe](https://prql.r-universe.dev/prqlr) repository.

```r
# Install from R-universe
install.packages("prqlr", repos = "https://prql.r-universe.dev")
```

For source installation, pre-built Rust libraries may be available
if the environment variable `NOT_CRAN` is set to `"true"`. (Or, set `LIBPRQLR_BUILD` to `"false"`)

```r
Sys.setenv(NOT_CRAN = "true")
install.packages("prqlr")
```

Or, the Rust toolchain (Rust `r RcppTOML::parseTOML("src/rust/Cargo.toml")$package$"rust-version"` or later)
must be configured to build the Rust library.

Please check the repository for about Rust code in R packages.

## Examples

```{r}
library(prqlr)

"from mtcars | filter cyl > 6 | select {cyl, mpg}" |>
prql_compile() |>
cat()
```

PRQL's pipelines can be joined by the newline character (`\n`), or actual newlines in addition to `|`.

```{r}
"from mtcars \n filter cyl > 6 \n select {cyl, mpg}" |>
prql_compile() |>
cat()
```

```{r}
"from mtcars
filter cyl > 6
select {cyl, mpg}" |>
prql_compile() |>
cat()
```

Thanks to the `{tidyquery}` package,
we can even convert a PRQL query to a SQL query and then to a `{dplyr}` query!

```{r}
"from mtcars
filter cyl > 6
select {cyl, mpg}" |>
prql_compile() |>
tidyquery::show_dplyr()
```

## `{knitr}` integration

Using `{prqlr}` with `{knitr}` makes it easy to create documents that lists PRQL queries and a translated SQL queries,
or documents that lists PRQL queries and tables of data retrieved by PRQL queries.

Please check the vignette `vignette("knitr", "prqlr")` for details.