tidyverse / dplyr

dplyr: A grammar of data manipulation
https://dplyr.tidyverse.org/
Other
4.76k stars 2.12k forks source link

Breaking change: mutate_at no longer uses names provided in vars(...) #2594

Closed odeleongt closed 7 years ago

odeleongt commented 7 years ago

Colwise verb mutate_at allowed specification of new names for variables under vars(...), thus we could create new, modified, variables without changing the original ones.

It worked at least under dplyr version 0.5.0.9001 ref 3525de3...

devtools::install_github("hadley/dplyr", ref = "3525de33010c80c63d527de91f8ae200d822dc98")

library(package = dplyr)

mtcars %>%
    mutate_at(vars(fuel_economy = mpg), funs(. + 1)) %>%
    filter(fuel_economy < 12)

##    mpg cyl disp  hp drat    wt  qsec vs am gear carb fuel_economy
## 1 10.4   8  472 205 2.93 5.250 17.98  0  0    3    4         10.4
## 2 10.4   8  460 215 3.00 5.424 17.82  0  0    3    4         10.4

But stopped working under dplyr version 0.5.0.9001 ref 9a994cf...

devtools::install_github("hadley/dplyr", ref = "9a994cff81b76d17e9943ee7ac1e60bd7361e049")

library(package = dplyr)

mtcars %>%
    mutate_at(vars(fuel_economy = mpg), funs(. + 1)) %>%
    filter(fuel_economy < 12)

## Error in filter_impl(.data, quo) : object 'fuel_economy' not found

Will dplyr keep the feature to provide new names to variable in colwise verbs?

hadley commented 7 years ago

@lionel- can you please take a look

Minimal reprex:

library(dplyr, warn.conflicts = FALSE)

tibble(x = 1:3) %>%
  mutate_at(vars(y = x), funs(. + 1))
#> # A tibble: 3 × 1
#>       x
#>   <dbl>
#> 1     2
#> 2     3
#> 3     4