Generally, if I want to save something into an object when using the pipe, I do it at the beginning. For example:
library(tidyverse) cty_mpg <- mpg %>% group_by(cyl) %>% summarize(cty_mean = mean(cty))
I read a blog post a while back (can’t find it now, maybe someone else can?) that advocated using
-> instead at the end of the pipeline. So the above example would turn into:
mpg %>% group_by(cyl) %>% summarize(cty_mean = mean(cty)) -> cty_mpg
This seems more natural because the last step after building up the pipeline is to store the result. But, as much as I think it makes logical sense, I haven’t adopted this style with my own code yet because it just feels… weird. I don’t know, maybe I’m just stuck in my ways.
So I was hoping to get others thoughts. Which approach do you prefer and why?