-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Description
Looks like from the version v1.1.0, the function rename_with will get error if no variables are selected. In my case, I have data from many spreedsheets, and I need to rename variable ABC to AAA if variable ABC is available. If ABC doesn't exist in one spreadsheet, then nothing to do. Actually I have several variables like ABC. If I have to judge if all those variables exist in all the spreedsheets, the logic will be quality complex. So I have tired below. It seems rename_with has a bug for the last piece of code.
# library
library(dplyr)
test=iris
names(test)
# this code works for the verion lower than v1.1.0
test0<-test %>% rename_with("newname",starts_with("Spec2ie"))
# this code works and no variable name changes
test1<-test %>% rename_with(~character(0),starts_with("Spec2ie"))
names(test1)
# this code don't work
test2<-test %>% rename_with(~ifelse(length(.)==0,character(0),"newname"),
starts_with("Spec2ie"))
# Error in `rename_with()`:
# ! `.fn` must return a vector of length 0, not 1.
# Run `rlang::last_trace()` to see where the error occurred.
Metadata
Metadata
Assignees
Labels
No labels