The pipe in R
Chaining operations left to right instead of nesting.
library(dplyr)
result <- mtcars %>%
filter(cyl == 4) %>%
select(mpg, wt, hp) %>%
arrange(desc(mpg)) %>%
head(5)
native <- mtcars |>
subset(mpg > 30) |>
nrow()
How it works
%>%passes the left value into the next call.- Each verb reads as a step in one pipeline.
|>is the native pipe with the same idea.
Keywords and builtins used here
arrangedescfilterheadlibrarynrowselectsubset
The run, in numbers
- Lines
- 11
- Characters to type
- 160
- Tokens
- 50
- Three-star pace
- 90 tpm
At the three-star pace of 90 tokens a minute, this run takes about 33 seconds.
Step 4 of 4 in Tibbles & columns, step 4 of 27 in dplyr.