%.>%
dot arrow pipe is a strict pipe with intended semantics:
“
a %.>% b
” is to be treated as if the user had written “{ . <- a; b };
” with “%.>%
” being treated as left-associative.
That is: %.>%
does not alter any function arguments that are not explicitly named. %.>%
is designed to be explicit and simple.
The effect looks is show below.
The following two expressions should be equivalent:
library("wrapr")
cos(exp(sin(4)))
## [1] 0.8919465
4 %.>% sin(.) %.>% exp(.) %.>% cos(.)
## [1] 0.8919465
The notation is quite powerful as it treats pipe stages as expression parameterized over the variable “.
”. This means you do not need to introduce functions to express stages. The following is a valid dot-pipe:
1:4 %.>% .^2
## [1] 1 4 9 16
The notation is also very regular in that expressions have the same iterpretation be then surrounded by parenthesis, braces, or as-is:
1:4 %.>% { .^2 }
## [1] 1 4 9 16
1:4 %.>% ( .^2 )
## [1] 1 4 9 16
Regularity can be a big advantage in teaching and comprehension. Please see “In Praise of Syntactic Sugar” for more details.