Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save output between pipes in dplyr [duplicate]

Tags:

r

pipe

dplyr

I am writing a function with several pipes. I would like to save some of the steps as .tbl or data frame before the last pipe. For instance: a %>% b %>% c, I would like to save the step 'c', but also want the step 'b'.

I know that one option is to do two pipes, but I believe that must have a better way.

cars %>% mutate(kmh = dist/speed) %>% summary()

like image 317
Felipe Dalla Lana Avatar asked Apr 19 '18 16:04

Felipe Dalla Lana


1 Answers

Thanks for the help. I found a better solution using braces{} and ->>. See below

   c = cars %>% mutate(var1 = dist*speed)%>%
   {. ->> b } %>%   #here is save
   summary()
   c
   head(b)
like image 183
Felipe Dalla Lana Avatar answered Oct 13 '22 16:10

Felipe Dalla Lana