[datatable-help] Access to local variables in "j" expressions

Short, Tom TShort at epri.com
Sat May 8 13:34:31 CEST 2010


I think it's a bug, Johann. I'll dig deeper. Thanks for reporting it.

- Tom
 

> -----Original Message-----
> From: datatable-help-bounces at lists.r-forge.r-project.org 
> [mailto:datatable-help-bounces at lists.r-forge.r-project.org] 
> On Behalf Of Johann Hibschman
> Sent: Friday, May 07, 2010 4:53 PM
> To: datatable-help at lists.r-forge.r-project.org
> Subject: [datatable-help] Access to local variables in "j" expressions
> 
> 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
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/d
atatable-help
> 


More information about the datatable-help mailing list