Behind the scenes, x %>% f(y) turns into f(x, y), and x %>% f(y) %>% g(z)turns into g(f(x, y), z) and so on.
The pipe operator enable us to focus on the transformations, not what’s being transformed. It also makes the code easier to read: replace %>% with “then” when reading code.
In R 4.1, a built-in pipe operator is introduced: |>. This operator doesn’t rely on third-party packages and may be faster. But it lacks two important features that %>% has
represent the value being piped in by ., as in the above example
when you pipe into a function with no other arguments, you can omit the parentheses ()
Footnotes
Rene Magritte has a famous painting that says “This is not a pipe.” ↩