Closed renkun-ken closed 10 years ago
For example,
library(fUnitRoots)
Pipe(rnorm(100))$
cumsum()$
adfTest(lags = 5)$
test$
statistic
$value : numeric
------
Dickey-Fuller
-2.033778
This implementation often leads to potential confusion.
Consider a data frame containing a column named select
, if dplyr is used to select the columns, the column will be singled out and select()
would be ignored.
If rule 4 has higher priority, $
is still overloaded by too much potential functionality.
A new closure .()
is added to Pipe
object. For .(y)
,
y
is a name
then it gets getElement(x,"y")
which also works for S4 object.y
is a call
then it performs lambda piping to .
or user-defined symbol.This allows the following usage:
Pipe(mtcars)$
.(lm(mpg ~ cyl + wt, data = .))$
.(coefficients)
$value : numeric
------
(Intercept) cyl wt
39.686261 -1.507795 -3.190972
For S4 object,
library(fUnitRoots)
Pipe(rnorm(100))$
cumsum()$
adfTest(lags = 5)$
.(test)$
.(statistic)
$value : numeric
------
Dickey-Fuller
-1.283631
Then .()
incorporates the functionality of fun()
which may be deprecated in future version for potential name conflicts.
Now, Pipe(x)$.(...)
closure in Pipe
object works in exactly the same way with x %>>% (...)
.
Consider supporting the following piping mechanism for
Pipe(x)$y
y
inPipe
object environment ($value
,$fun
)x
in Pipe is S4, get sloty
fromx
.x
in Pipe is list or vector, get element namedy
fromx
.y
inparent.frame()
This allows the following usage: