-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
duplicateprogrammingparameterizing queries: get, mget, eval, envparameterizing queries: get, mget, eval, env
Description
Suppose I have a data.table created as follows:
dt <- data.table(x1 = 1:10, x2 = 10:1, x3 = 1:10)I need to do calculations with dynamically determined symbols within j like
s1 <- "x2"
s2 <- "x3"
Two approaches can do the work:
> dt[, get(s1) * get(s2)]
[1] 10 18 24 28 30 30 28 24 18 10
> dt[, .SD[[1]] * .SD[[2]], .SDcols = c(s1, s2)]
[1] 10 18 24 28 30 30 28 24 18 10But if the data is very big and by= is used, the performance can significantly decay. Also the first approach using get() has scoping problem if s1 or s2 are themselves columns of dt.
Is there any possibility that makes it easier to use dynamically determined symbol without such significant performance decay and scoping problem?
For example, something like
dt[, ..s1 * ..s2]which is inspired by the ..x notation introduced lately.
Metadata
Metadata
Assignees
Labels
duplicateprogrammingparameterizing queries: get, mget, eval, envparameterizing queries: get, mget, eval, env