-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
rename_with
with empty column selection fails w/ dplyr 1.1.0.
#6688
Comments
Apparently, the following example is working: library(dplyr, warn.conflicts = FALSE)
tibble(col = c(1,3)) %>%
rename_with(
.cols = contains("test"),
.fn = toupper
)
#> # A tibble: 2 × 1
#> col
#> <dbl>
#> 1 1
#> 2 3 Created on 2023-02-06 with reprex v2.0.2 I don't understand why though. |
Okay, I think, I get it now. In this case, the behavior seems actually fine and consistent to me. Sorry for the noise. |
Technically that's a bug with library(dplyr, warn.conflicts = FALSE)
df <- tibble(col = c(1, 3))
df |>
rename_with(
.cols = contains("test"),
.fn = ~ paste0("blah.", ., recycle0 = TRUE)
)
#> # A tibble: 2 × 1
#> col
#> <dbl>
#> 1 1
#> 2 3
df |>
rename_with(
.cols = contains("test"),
.fn = ~ stringr::str_c("blah.", .)
)
#> # A tibble: 2 × 1
#> col
#> <dbl>
#> 1 1
#> 2 3 Created on 2023-02-06 with reprex v2.0.2 So I'm not sure how we should handle this in dplyr. |
It's the same with |
Hi,
due to the size check in the new dplyr version, dplyr 1.1.0, renames with empty column selections don't work anymore (since it expects a vector of functions of size 0).
This is of course not a big problem when used interactively, since one can simply omit the whole statement.
But when used programmatically in a data pipeline it forces the programmer to always treat this case separately (if for instance the .cols argument is defined by external dynamical parameters).
I would expect this function to simply do nothing if no columns are selected, and not throw an error.
Created on 2023-02-06 with reprex v2.0.2
The text was updated successfully, but these errors were encountered: