[datatable-help] Access to local variables in "j" expressions
Johann Hibschman
jhibschman at gmail.com
Fri May 7 22:53:02 CEST 2010
I'm just taking a look at data.table again, now that 1.4.1 has been
released. I tried the following:
dt.test <- data.table(n=c("a","a","b"), x=1:3, key="n")
global.sum7 <- function (y) {
sum(y) + 7
}
test.1 <- function (dt) {
local.sum7 <- global.sum7
dt[, list(out=local.sum7(x)), by=n]
}
test.1(dt.test)
This failed, with 'Error in eval(expr, envir, enclos) : could not
find function "local.sum7"'. Looking at the documentation, I see:
The j expression 'sees' variables in the calling frame and above
including .GlobalEnv, see the examples. This is base R
functionality from eval() and with().
That led me to think that the above would work. Is this a bug, or am I
not understanding something?
Thanks,
Johann
More information about the datatable-help
mailing list