Closed renkun-ken closed 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
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
> local({i <- 1; Pipe(1:3)$fun(list.filter(.,. <= i))})
<Pipe>
$value : integer
[1] 1
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)})
This should not be identified as a bug of pipeR.