It is a little tricky to show my problem with real data but I hope the following explains:
data_frame(a=c(1,2), b=c(3,4)) %>%
rowwise %>%
mutate(c = a*b, d = c-1, e=c+2) %>%
ungroup
In the above example of course the rowwise
is not needed.
Now lets suppose that the calculation to make c
is both time consuming, c
is a large object and not vectorized.
So you don't want to have to execute it twice and you want it to be cleared from the memory after each row calculation happens.
Is there a clever way to do this? Perhaps with purrr::map
?