[Rd] New pipe operator
Duncan Murdoch
murdoch@dunc@n @end|ng |rom gm@||@com
Fri Dec 4 12:50:39 CET 2020
Just saw this on the R-devel news:
R now provides a simple native pipe syntax ‘|>’ as well as a shorthand
notation for creating functions, e.g. ‘\(x) x + 1’ is parsed as
‘function(x) x + 1’. The pipe implementation as a syntax transformation
was motivated by suggestions from Jim Hester and Lionel Henry. These
features are experimental and may change prior to release.
This is a good addition; by using "|>" instead of "%>%" there should be
a chance to get operator precedence right. That said, the ?Syntax help
topic hasn't been updated, so I'm not sure where it fits in.
There are some choices that take a little getting used to:
> mtcars |> head
Error: The pipe operator requires a function call or an anonymous
function expression as RHS
(I need to say mtcars |> head() instead.) This sometimes leads to error
messages that are somewhat confusing:
> mtcars |> magrittr::debug_pipe |> head
Error: function '::' not supported in RHS call of a pipe
but
mtcars |> magrittr::debug_pipe() |> head()
works.
Overall, I think this is a great addition, though it's going to be
disruptive for a while.
Duncan Murdoch
More information about the R-devel
mailing list