Dplyr: amount inside a sequential mutant

library(dplyr) tib <- tibble(a = c(1,2,3)) 

The following works as expected:

 tib %>% mutate(b = a^2, c = sqrt(b)) # A tibble: 3 x 3 abc <dbl> <dbl> <dbl> 1 1 1 1 2 2 4 2 3 3 9 3 tib %>% mutate(b = a^2, c = sum(a)) # A tibble: 3 x 3 abc <dbl> <dbl> <dbl> 1 1 1 6 2 2 4 6 3 3 9 6 tib %>% mutate(b = a^2) %>% mutate(c = sum(b)) # A tibble: 3 x 3 abc <dbl> <dbl> <dbl> 1 1 1 14 2 2 4 14 3 3 9 14 

It is impossible:

 tib %>% mutate(b = a^2, c = sum(b)) # A tibble: 3 x 3 abc <dbl> <dbl> <dbl> 1 1 1 1.482197e-323 2 2 4 1.482197e-323 3 3 9 1.482197e-323 

I expect the result in column c will be the same as above, 14 worldwide. Any insight on what I'm doing wrong?

+5
source share
1 answer

I checked both versions of dplyr : it looks like a bug in the new tidyeval engine. I filed an error on Github .


Update:

This is now fixed. Issue . The new version dplyr 0.7.1 and higher no longer has this problem.

+3
source

Source: https://habr.com/ru/post/1268916/


All Articles