I am not sure if it is a good or bad idea. But let’s play with it a bit, and perhaps readers can submit their experience and opinions in the comments section.
Right assignment is a bit of an oddity in programming languages. Offhand I can think of a few programming languages that use it: COBOL, TI-Basic, and Forth (due to its value-stack notation).
Frankly I thought right assignment was prohibited in Hadley Wickham’s own style guide. But as Gabe Becker taught me a while ago: there isn’t actually any right-arrow in
R (so maybe “Use
=, for assignment.” allows
substitute(5 -> x) # x <- 5
R pipes are very closely related to right assignment notation, so once you allow right assignment you don’t actually need pipes in the current
R sense (though other forms of pipes such as Unix pipes would be a great addition).
The idea of having a canonical “pronunciation” for symbols is not a new one. It is fairly standard practice in the Unix community (one reference here). The McIlroy Unix pipe “
|” (which streams partial results, resulting in very powerful concurrent composition) is said to be read as “pipe”, “pipe to”, “to”, “thru” (and a few more variations). In this era of keyboard shortcuts it is worth considering more verbose piping operators.
Let’s try the idea.
library("dplyr") #> Attaching package: 'dplyr' #> The following objects are masked from 'package:stats': #> #> filter, lag #> The following objects are masked from 'package:base': #> #> intersect, setdiff, setequal, union d <- data.frame(x = 1:3) `%then%` <- magrittr::`%>%` d %then% mutate(., y = x + 1) %then% knitr::kable(.) #> Error in pipes[[i]]: subscript out of bounds
I’d say this fails on at least two counts, the first “
%then%” doesn’t seem grammatical (as
d is a noun), and
magrittr pipes can’t be associated with a new name (as they are implemented by looking for theirselves by name in captured unevaluated code).
wrapr dot arrow pipe can take on new names.
Let’s try a variation, using a traditional pronunciation: “to”.
`%to%` <- wrapr::`%.>%` d %to% mutate(., y = x + 1) %to% knitr::kable(.)
I am still not sure about the above notation one way or the other. Notational prescriptions are at best proposals or “requests for comment”, and need to consider context and precedent to be useful.
Data Scientist and trainer at Win Vector LLC. One of the authors of Practical Data Science with R.