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

https://github.com/moodymudskipper/qplyr

Delayed Evaluation With tidyverse Verbs
https://github.com/moodymudskipper/qplyr

Last synced: 2 days ago
JSON representation

Delayed Evaluation With tidyverse Verbs

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
options(tidyverse.quiet = TRUE)
```

# qplyr

Experimental!
`r lifecycle::badge("experimental")`

Delayed evaluation with tidyverse verbs, mimicking {dbplyr}'s API.

The benefits are :

* We can keep expensive calculations for later, calling `collect()` when needed
* The object contains its execution plan that we can see more clearly with `show_query()`
* We can even save a non computed object as a RDS and load it to compute it in a new session

It contains no exported function, it just registers methods for the "quosure" class.

## Installation

Install with:

``` r
remotes::install_github("moodymudskipper/qplyr")
```

## Example

We start from a quosure on a local or lazy data frame and transform it with tidyverse functions as we would usually do

```{r example}
library(tidyverse)
library(qplyr)

f1 <- function(x, ...) {
mutate(x, a = speed * dist, ...)
}

f2 <- function(x, max_speed, other_cond) {
min_speed <- 16
filter(x, speed >= min_speed, speed <= {{ max_speed }}, {{ other_cond }})
}

q1 <- quo(cars) |> # note: we could quo a lazy table too
f1(b = speed /dist) |>
f2(17, dist == 32)
```

q1 is a regular quosure and prints like one:

```{r}
q1
```

The show_query() method prints friendlier and shows environments :

* next to generics: the env where they were called
* next to args (squashed quosures), the quosure's env label.

```{r}
show_query(q1)
```

The collect method is really just `rlang::eval_tidy()`

```{r}
collect(q1)
```