Skip to content
Prev 57544 / 63421 Next

should base R have a piping operator ?

Dear R-devel,

The most popular piping operator sits in the package `magrittr` and is used
by a huge amount of users, and imported /reexported by more and more
packages too.

Many workflows don't even make much sense without pipes nowadays, so the
examples in the doc will use pipes, as do the README, vignettes etc. I
believe base R could have a piping operator so packages can use a pipe in
their code or doc and stay dependency free.

I don't suggest an operator based on complex heuristics, instead I suggest
a very simple and fast one (>10 times than magrittr in my tests) :

`%.%` <- function (e1, e2) {
  eval(substitute(e2), envir = list(. = e1), enclos = parent.frame())
}

iris %.% head(.) %.% dim(.)
#> [1] 6 5

The difference with magrittr is that the dots must all be explicit (which
sits with the choice of the name), and that special magrittr features such
as assignment in place and building functions with `. %>% head() %>% dim()`
are not supported.

Edge cases are not surprising:

```
x <- "a"
x %.% quote(.)
#> .
x %.% substitute(.)
#> [1] "a"

f1 <- function(y) function() eval(quote(y))
f2 <- x %.% f1(.)
f2()
#> [1] "a"
```

Looking forward for your thoughts on this,

Antoine

Thread (33 messages)

Ant F should base R have a piping operator ? Oct 5 Jeff Ryan should base R have a piping operator ? Oct 5 John Mount should base R have a piping operator ? Oct 5 Hugh Marera should base R have a piping operator ? Oct 5 David Hugh-Jones should base R have a piping operator ? Oct 5 Ant F should base R have a piping operator ? Oct 5 John Mount should base R have a piping operator ? Oct 5 Rui Barradas should base R have a piping operator ? Oct 5 Iñaki Ucar should base R have a piping operator ? Oct 5 Iñaki Ucar should base R have a piping operator ? Oct 5 Ant F should base R have a piping operator ? Oct 5 Hugh Marera should base R have a piping operator ? Oct 5 Iñaki Ucar should base R have a piping operator ? Oct 5 Ant F should base R have a piping operator ? Oct 5 Gabriel Becker should base R have a piping operator ? Oct 5 Joris Meys should base R have a piping operator ? Oct 6 Iñaki Ucar should base R have a piping operator ? Oct 6 John Mount should base R have a piping operator ? Oct 6 Duncan Murdoch should base R have a piping operator ? Oct 6 Ant F should base R have a piping operator ? Oct 6 Lionel Henry should base R have a piping operator ? Oct 7 Duncan Murdoch should base R have a piping operator ? Oct 7 Lionel Henry should base R have a piping operator ? Oct 7 Duncan Murdoch should base R have a piping operator ? Oct 7 Lionel Henry should base R have a piping operator ? Oct 7 Luke Tierney should base R have a piping operator ? Oct 7 Lionel Henry should base R have a piping operator ? Oct 7 Luke Tierney should base R have a piping operator ? Oct 7 Kevin Ushey should base R have a piping operator ? Oct 7 Lionel Henry should base R have a piping operator ? Oct 7 Lionel Henry should base R have a piping operator ? Oct 7 Luke Tierney should base R have a piping operator ? Oct 7 Luke Tierney should base R have a piping operator ? Oct 7