renkun-ken / pipeR

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

Operator should also work with Pipe object #33

Closed renkun-ken closed 10 years ago

renkun-ken commented 10 years ago

Currently, %>>% does not seamlessly work with Pipe object (directly with its inner value). Consider to make them compatible with each other so that they can co-work like

> Pipe(1:3) %>>% c(4)
$value : numeric 
------
[1] 1 2 3 4
> Pipe(rnorm(10)) %>>% summary()
$value : summaryDefault table 
------
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
-2.0540 -0.9229  0.1231 -0.2102  0.5831  0.9954 

This will allow the resulted Pipe persist the feature of command chaining with $.

> z <- Pipe(1:5) %>>% (.^2)
> z
$value : numeric 
------
[1]  1  4  9 16 25
> z$mean()
$value : numeric 
------
[1] 11

However, it is not recommended to use both piping in one pipeline, and benchmark tests show that this feature may notably lower the performance of operator by up to 40% but the performance loss is insignificant in practical use for data manipulation.

renkun-ken commented 10 years ago

But I think this feature will allow the mixed use of Pipe and %>>%, which is not a good way to use them. Push this only to feature/cowork and it is unlikely to go to 0.4.