Dplyr: Reuse newly created variable in the same `mutate` call does not work anymore?

Created on 17 Mar 2020  Â·  1Comment  Â·  Source: tidyverse/dplyr

Hello,

The following code used to work in dplyr (not too long ago) but not with the latest one here. Did I miss something?

Thanks!


library(dplyr)

### used to work
iris %>% 
  mutate(Species2 = Species,
         Species2 = paste0(Species2, ":~", Sepal.Width))
#> Error: `mutate()` argument `Species2` errored.
#> i `Species2` is `paste0(Species2, ":~", Sepal.Width)`.
#> x object 'Species2' not found

Created on 2020-03-17 by the reprex package (v0.3.0)

bug

Most helpful comment

Thanks @tungmilan! This is obviously a bug. Here's a slightly more minimal reprex:

library(dplyr, warn.conflicts = FALSE)

df <- data.frame(x = 1, y = 2)
df %>% mutate(x2 = x, x3 = x2 + 1)
#> Error: `mutate()` argument `x3` errored.
#> ℹ `x3` is `x2 + 1`.
#> x object 'x2' not found
df %>% mutate(x2 = x + 0, x3 = x2 + 1)
#>   x y x2 x3
#> 1 1 2  1  2

Created on 2020-03-17 by the reprex package (v0.3.0)

@romainfrancois this looks related to the symbol only stuff you were working on recently.

>All comments

Thanks @tungmilan! This is obviously a bug. Here's a slightly more minimal reprex:

library(dplyr, warn.conflicts = FALSE)

df <- data.frame(x = 1, y = 2)
df %>% mutate(x2 = x, x3 = x2 + 1)
#> Error: `mutate()` argument `x3` errored.
#> ℹ `x3` is `x2 + 1`.
#> x object 'x2' not found
df %>% mutate(x2 = x + 0, x3 = x2 + 1)
#>   x y x2 x3
#> 1 1 2  1  2

Created on 2020-03-17 by the reprex package (v0.3.0)

@romainfrancois this looks related to the symbol only stuff you were working on recently.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

burkovae picture burkovae  Â·  3Comments

slyrus picture slyrus  Â·  3Comments

Prometheus77 picture Prometheus77  Â·  4Comments

ggrothendieck picture ggrothendieck  Â·  4Comments

steromano picture steromano  Â·  4Comments