Does replyr::let work with data.table?
Win-Vector Blog 2017-01-11
I’ve been asked if the adapter “let
” from our R
package replyr
works with data.table
.
My answer is: it does work. I am not a data.table
user so I am not the one to ask if data.table
benefits a from a non-standard evaluation to standard evaluation adapter such as replyr::let
.
Using replyr::let
with data.table
looks like the following:
library("data.table")library("replyr")data("iris", package= "datasets")iris.dt <- data.table(iris)# non-standard evaluation, column names hard-codediris.dt[, mean(Sepal.Length), by=Species]# standard evaluation, column names parameterizedlet( list(GROUPCOL='Species', DATACOL='Sepal.Length'), iris.dt[, mean(DATACOL), by=GROUPCOL])# alternate (development/Github) operator notations:# "let in"list(GROUPCOL='Species', DATACOL='Sepal.Length') %:% iris.dt[, mean(DATACOL), by=GROUPCOL]# "eval over"iris.dt[, mean(DATACOL), by=GROUPCOL] %//% list(GROUPCOL='Species', DATACOL='Sepal.Length')
I’ve generated some timings to show there is some overhead in the translation (especially on trivial examples):
If any data.table
users want to comment if this is useful or not, I’d be happy to hear from you.