-
Notifications
You must be signed in to change notification settings - Fork 301
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.sf
doesn't pass arguments as per dplyr::rename_with
help file
#2310
Comments
I am seeing > nc |>
rename_with(str_remove, pattern = "\\d")
Error in .fn(names(agr)) : argument "pattern" is missing, with no default
> traceback()
6: vctrs::vec_size_common(string = string, pattern = pattern, replacement = replacement,
.call = error_call)
5: check_lengths(string, pattern, replacement)
4: str_replace(string, pattern, "")
3: .fn(names(agr))
2: rename_with.sf(nc, str_remove, pattern = "\\d")
1: rename_with(nc, str_remove, pattern = "\\d") is that the problem you are referring to? |
Yes sorry, I'm not sure what happened with my example code above - had assumed it had run the same as that before I posted it! Edit - I see I forgot to run the |
Thanks! |
As a brief question - in #2312 I noted that the When I added testing to the updated |
The docs of |
It works for the column names well, but the second step (the fn = function(x) paste0(x, "_renamed")
# Before renaming:
nc %>% attr("agr")
#> AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID
#> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
#> BIR74 SID74 NWBIR74 BIR79 SID79 NWBIR79
#> <NA> <NA> <NA> <NA> <NA> <NA>
#> Levels: constant aggregate identity
# After renaming:
nc %>% rename_with(fn, c(FIPS, FIPSNO)) %>% attr("agr")
#> <NA> <NA> <NA> <NA> <NA>
#> <NA> <NA> <NA> <NA> <NA>
#> FIPS_renamed FIPSNO_renamed <NA> <NA> <NA>
#> <NA> <NA> <NA> <NA> <NA>
#> <NA> <NA> <NA> <NA>
#> <NA> <NA> <NA> <NA>
#> Levels: constant aggregate identity Had only discovered when trying to write a test which fails: fn = function(x) paste0(x, "_renamed")
expect_identical(nc %>% rename_with(fn, c(FIPS, FIPSNO)),
nc %>% rename(FIPS_renamed = FIPS, FIPSNO_renamed = FIPSNO)) |
As discovered in a SO post, when renaming an
sf
object withrename_with.sf
, it doesn't pass the arguments to the inner function via...
as expected:Suggested fix (pr to follow) would be to add
...
to.fn()
call here:sf/R/tidyverse.R
Line 272 in 99d6565
The text was updated successfully, but these errors were encountered: