renkun-ken / pipeR

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

I(x) does not work with function without calling #51

Closed renkun-ken closed 10 years ago

renkun-ken commented 10 years ago
> 1:10 %>>% (function(x,y) x + y)(2)
 [1]  3  4  5  6  7  8  9 10 11 12
> 1:10 %>>% (function(x,y) x + y)
function(x,y) x + y
<environment: 0x000000000e7c1fd0>
> 1:10 %>>% I(function(x,y) x + y)(2)
 [1]  3  4  5  6  7  8  9 10 11 12
> 1:10 %>>% I(function(x,y) x + y)
Error in expr[[1L]] : object of type 'closure' is not subsettable

This should work for building closure:

> p <- function(y) { function(x) x + y }
> 1:10 %>>% I(p(1))
Error in expr[[1L]] : object of type 'closure' is not subsettable
> 1:10 %>>% I(p(1))()
 [1]  2  3  4  5  6  7  8  9 10 11