library(knitr) library(data.table) library(dtplyr) knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-", cache = TRUE )
dplyr
's verbs with data.table
This is WIP. Feel free to help :)
Aliases also provided to resemble SQL syntax more closely.
Powered mostly by rlang
.
The basic idea is to parse the input from all the verbs and create a single expression that, after evaluation,
simply delegates all the actual computations to data.table
,
letting it handle all optimizations as usual.
# the expression is what matters here, input is left empty data.table() %>% select(.(col)) %>% where(var == val) %>% order_by(v)
The input data.table
is alwas assigned in the evaluation's environment as the .DT_
variable.
The evaluation environment's enclosing environment should be the one where the input is first captured,
at least that's the idea.
In many cases character input can also be supported,
which could be useful for other packages that use data.table
.
data("mtcars") as.data.table(mtcars) %>% select(mpg:disp) %>% where(vs == 0L, am == 0L, .collapse = `|`) %>% order_by(mpg, -cyl) %>% eval_expr as.data.table(mtcars) %>% select("mpg", "cyl", "disp", with = FALSE) %>% where("vs == 0L", "am == 0L", .collapse = `|`, .parse = TRUE) %>% order_by("mpg", "-cyl", .parse = TRUE) %>% eval_expr
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.