-
Notifications
You must be signed in to change notification settings - Fork 39
Closed
Description
Consider the following syntax:
x %>>% (~ expr) # evaluate expr with . = x and return x
x %>>% ((m) ~ expr) # evaluate expr with m = x and return xmtcars %>>%
(~ cat("Number of columns:",ncol(.),"\n")) %>>%
(mpg) %>>%
summaryNumber of columns: 11
Min. 1st Qu. Median Mean 3rd Qu. Max.
10.40 15.42 19.20 20.09 22.80 33.90
or
mtcars %>>%
((x) ~ cat("Number of columns:",ncol(x),"\n")) %>>%
(mpg) %>>%
summaryNumber of columns: 11
Min. 1st Qu. Median Mean 3rd Qu. Max.
10.40 15.42 19.20 20.09 22.80 33.90
where (~ expr) or ((x) ~ expr) indicates that the output of this will be ignored and the input will be returned, thus only for side effect (only one side is stressed in the formula, also looks like expr is evaluated as a side branch)
Note that all syntax in () automatically applies to .() in Pipe, therefore,
Pipe(mtcars)$
.(~ cat("Number of columns:",ncol(.),"\n"))$
.(mpg)$
summary()Number of columns: 11
$value : summaryDefault table
------
Min. 1st Qu. Median Mean 3rd Qu. Max.
10.40 15.42 19.20 20.09 22.80 33.90