[Rd] Generalised piping into operators

Michael Milton ttm|gue|tt @end|ng |rom gm@||@com
Fri Apr 21 10:35:54 CEST 2023


I just checked out R-devel and noticed that the new "pipe extractor"
capability coming in 4.3 only works for the 4 extractor operators, but no
other standard operators like +, *, %*% etc, meaning that e.g. mtcars |>
as.matrix() |> _ + 1 |> colMeans() is a syntax error. In addition, we are
still subject to the restriction that the functions on the RHS of a pipe
can't have special names, so mtcars |> as.matrix() |> `+`(1) |> colMeans() is
also a syntax error.

Either option would be great, as I find it much cleaner to coordinate a
sequence of function calls using pipes rather than nested function calls or
using temporary variables.

May I enquire why both of these expressions are disallowed, and if it might
be possible to help remove one or both of these restrictions? There is some
discussion at
https://stat.ethz.ch/pipermail/r-devel/2020-December/080210.html but the
thread is mostly concerned with other things like the placeholder and
whether or not parentheses can be omitted. My naive view is that piping
into a special operator function like `+` would be the least ambiguous: `+`
presumably parses to the same type of token as `colMeans` does, so the
function parse tree seems like it would work fine if this was allowed in a
pipe.

Cheers,
Michael

	[[alternative HTML version deleted]]



More information about the R-devel mailing list