New Pipe in R

You can read more in Michael Barrowman’s post

But the basic idea is that using the new pipe |> from the magrittr library is much faster than your old pipe %>%

# install.packages("magrittr")
remotes::install_github("Myko101/magrittrclassic")
library("magrittr")
library("tidyverse")
doubler <- function(val) 2*val
x <- 1:10
bm <- bench::mark(
  standard = doubler(x),
  magrittrclassic = x %>>% doubler(),
  magrittr = x %>% doubler(),
  base = x |> doubler()
)
ggplot2::autoplot(bm)
bm2 <- bench::mark(
  standard = (function(y) 2*y)(x),
  magrittrclassic = x %>>% {2*.},
  magrittr = x %>% {2*.},
  base = x |> \(y) 2*y
)
ggplot2::autoplot(bm2)
Mike Nguyen, PhD
Mike Nguyen, PhD
Visiting Professor of Data Sciences and Operations

My research interests include marketing, and social science.

Next
Previous

Related