The first time I ever saw that you could do that was in a blog post about stringing at the end of the a series of pipes. I thought it was pretty neat (and actually used it a couple times), then had problems when I couldn't figure out why my code was messing up.
for example, this assigns a ggplot to 'plot':
df %>%
na.omit() %>%
ggplot(aes(x=x, y=y)) +
geom_line() -> plot
That is really confusing in that the way most people would read it is that it is something to be plotted. However, the assignment does occur and is masked. having 'plot <- df %>%' as the first line makes it clear that a new object is being created.
We actually had to modify our style guide to prevent the '->'
chasedehan|8 years ago
for example, this assigns a ggplot to 'plot': df %>% na.omit() %>% ggplot(aes(x=x, y=y)) + geom_line() -> plot
That is really confusing in that the way most people would read it is that it is something to be plotted. However, the assignment does occur and is masked. having 'plot <- df %>%' as the first line makes it clear that a new object is being created.
We actually had to modify our style guide to prevent the '->'
lionel-|8 years ago