renkun-ken / pipeR

Multi-Paradigm Pipeline Implementation
Other
169 stars 39 forks source link

Subsetting for Pipe does not work with data.table in local environment #34

Closed renkun-ken closed 10 years ago

renkun-ken commented 10 years ago
> library(pipeR)
> library(data.table)
data.table 1.9.2  For help type: help("data.table")
> z <- Pipe(data.table(x=1:3,y=rnorm(3),key="x"))
> z
$value : data.table data.frame 
------
   x          y
1: 1  1.2629543
2: 2 -0.3262334
3: 3  1.3297993
> local({i <- 1; z[J(i)]})
Error in eval(expr, envir, enclos) : object 'i' not found
renkun-ken commented 10 years ago

It is probably the problem of data.table. Consider the following test case:

First, define a function that simply subsets an object x:

test <- function(x,...) {
  x[...]
}

The run the following code:

> library(data.table)
> m <- data.table(x=1:3,key="x")
> m[J(1)]
   x
1: 1
> local({i <- 1; m[J(i)]})
   x
1: 1
> local({i <- 1; test(m, J(i))})
Error in eval(expr, envir, enclos) : object 'i' not found