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
- Host: GitHub
- URL: https://github.com/moodymudskipper/qplyr
- Owner: moodymudskipper
- License: other
- Created: 2023-08-31T21:51:38.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-03T12:12:51.000Z (over 1 year ago)
- Last Synced: 2025-04-12T20:52:23.068Z (2 days ago)
- Language: R
- Homepage:
- Size: 13.7 KB
- Stars: 16
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - moodymudskipper/qplyr - Delayed Evaluation With tidyverse Verbs (R)
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 sessionIt 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)
```