Was enjoying Gabriel’s article Pipes in R Tutorial For Beginners and wanted call attention to a few more pipes in R (not all for beginners).
- data.table has essentially used the square bracket sequence “
][
” in a manner equivalent to piping in R since about 2006. Here is an example. - The Bizarro Pipe “
->.;
” has always been possible in R, though I worked it out and started teaching it in 2016. And it is as quick to type as any other notation once you bind it to a keyboard shortcut. - Lately we have been using wrapr’s “dot pipe” “
%.>%
” under the theory that the placeholders may actually make sense as the primary objects in pipes (i.e., piping may be more about value sequencing than about function composition). - We toyed with the idea of adding a Kleisli arrow to R, and may get back to that one day.
The Kleisli arrow Khaleesi and dragon.
Categories: Tutorials
jmount
Data Scientist and trainer at Win Vector LLC. One of the authors of Practical Data Science with R.
Of course is one really wants to get up to mischief you can try unicode pipes:
Bind that to a keyboard shortcut and you can make everybody jealous (note: UTF8 is not recommended in R source code).
Unfortunately this doesn’t directly work for
magrittr
(likely due tomagrittr
capturing source code and then directly looking for the names of pipe stages):There’s also the lumberjack package offering a pipe that actually does something extra useful: it allows you to log changes in data.
And I just noticed the zeallot package with its unpacking assignment operator (not a pipe, but neat).