3 ms·
The best use of the pipe operator, in my opinion, is when every pipe followed by an end line, like this: data %>% filter(thing > 4) %>% mutate(new =
by laGrenouille 6y ago
The best use of the pipe operator, in my opinion, is when every pipe followed by an end line, like this:
data %>%
filter(thing > 4) %>%
mutate(new = fun(old)) %>%
group_by(var) %>%
summarize(new_mean = mean(new))
Then you are reading the code top-to-bottom, just like any other R script but without all of the temporary variables.
- disgruntledphd2 6y agoThis only really works if nothing ever fails. It's great for data analysis and terrible for programming. The reason it sucks for programming is because you can't debug it or inspect intermediate variables, which is really really annoying. It's great for one off transformations and plotting, but a really, really really bad idea for programming. Then you add NSE, which makes it hard to functionalise procedural pipes (especially for people who learned tidyverse) and it's a recipe for unmaintainable and profoundly annoying legacy code. That bring said,I love it for interactive analysis.