How can you implement F#’s forward pipe operator in R? The operator makes it possible to easily chain a sequence of calculations. For example, when you have an input data and want to call functions foo and bar in sequence, you can write:
data |> foo |> bar
Instead of writing bar(foo(data)). The benefits are that you avoid some parentheses and the computations are written in the same order in which they are executed (left-to-right). In F#, the operator is defined as follows:
let (|>) a f = f a
It would appear that %…% can be used for binary operators, but how would this work?
I don’t know how well it would hold up to any real use, but this seems (?) to do what you want, at least for single-argument functions …
For what it’s worth, as of now (3 December 2021), in addition to the
magrittr/tidyverse pipe (%>%), there also a native pipe|>in R (and an experimental=>operator that can be enabled in the development version): see here, for example.