renkun-ken / pipeR

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

Pipe object does not work with rlist in local environment #20

Closed renkun-ken closed 10 years ago

renkun-ken commented 10 years ago
> library(pipeR)
> library(rlist)
> local({i <- 10; Pipe(1:3)$list.map(. + i)})
Error in eval(expr, envir, enclos) : object 'i' not found
renkun-ken commented 10 years ago

But local environment works with built-in higher-order functions.

> local({i <- 10; Pipe(1:3)$sapply(function(j) j + i)})
<Pipe>
$value : numeric 
[1] 11 12 13
renkun-ken commented 10 years ago

List environment also works with local environment.

> local({ i <- 3; List(1:3)$map(. + i) })
<List environment>
$data : list 
[[1]]
[1] 4

[[2]]
[1] 5

[[3]]
[1] 6
renkun-ken commented 10 years ago

See https://github.com/renkun-ken/rlist/issues/50

renkun-ken commented 10 years ago
> local({i <- 1; Pipe(1:3)$fun(list.filter(.,. <= i))})
<Pipe>
$value : integer 
[1] 1
renkun-ken commented 10 years ago

The following code does not work too.

library(dplyr)
local({i <- 1;
Pipe(mtcars)$
  select(mpg,cyl,disp,hp)$
  filter(mpg <= median(mpg))$
  mutate(rmpg = mpg / max(mpg))$
  group_by(cyl)$
  do(data.frame(mean=mean(.$rmpg+i),median=median(.$rmpg+i))) []
})

but this works fine:

local({i <- 1; Pipe(mtcars)$filter(mpg <= median(mpg)+i)})
renkun-ken commented 10 years ago

This should not be identified as a bug of pipeR.