New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scoped rename functions don't work on grouped_df #2947
Comments
I've run into the same problem (in version 0.7.2). I noticed that the scoped So:
all work as expected. Sorry I can't be of more assistance, thanks for the awesome package! |
I've seen the same issue with version 0.7.3 (installed about a week ago): library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
obj <- data.frame(A_B = rep(1:2, each = 2), C_D = 1:4)
obj %>% rename_all(function(x) gsub("_", " ", x))
#> A B C D
#> 1 1 1
#> 2 1 2
#> 3 2 3
#> 4 2 4
obj %>% group_by(A_B) %>% rename_all(function(x) gsub("_", " ", x))
#> Error: All arguments must be named For the work I'm doing right now, a reasonable work-around is to add a |
It's not just grouped or not. The rename function is broken in 0.7.4. Even the iris example in the documentation fails. The select function appears to be OK, though, as observed above. From running "example(rename)": rename> # Renaming ----------------------------------------- A tibble: 150 x 1petal_length ... with 140 more rowsrename> # * rename() keeps all variables
locale: attached base packages: other attached packages: loaded via a namespace (and not attached): |
FTR, the examples using ungrouped select and rename, as in @dpeterson71's example, do work in the dev version (I'm currently running library(tidyverse)
# select() keeps only the variables you specify
s <- select(iris, petal_length = Petal.Length)
head(s)
#> petal_length
#> 1 1.4
#> 2 1.4
#> 3 1.3
#> 4 1.5
#> 5 1.4
#> 6 1.7
# rename() keeps all variables
r <- rename(iris, petal_length = Petal.Length)
head(r)
#> Sepal.Length Sepal.Width petal_length Petal.Width Species
#> 1 5.1 3.5 1.4 0.2 setosa
#> 2 4.9 3.0 1.4 0.2 setosa
#> 3 4.7 3.2 1.3 0.2 setosa
#> 4 4.6 3.1 1.5 0.2 setosa
#> 5 5.0 3.6 1.4 0.2 setosa
#> 6 5.4 3.9 1.7 0.4 setosa Created on 2018-01-16 by the reprex package (v0.1.1.9000). |
Following up on this I checked the behavior on two other machines and found the rename function working. The common feature of the working machines was rlang 0.1.6. The broken implementation has the development version of rlang (0.16.9002) installed as seen in the sessionInfo() in my initial comment. I'll file a bug report there. |
@dpeterson71 it works fine with 0.16.9003, so no need. |
@dpeterson71 @batpigandme @JohnMount FWIW rlang |
* Pass arguments directly to vars_rename() * Fix colwise renaming of variables on grouped data Closes #2947
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
In dplyr 0.7.1 these work:
But these don't (throw an error
All arguments must be named
):The text was updated successfully, but these errors were encountered: