r-lib/tidyselect

FR: add case sensibility option for `any_of()` and `all_of()`

Closed this issue · 3 comments

Hi,

Would it be possible to add a ignore.case=TRUE option in any_of() and all_of() like there is in starts_with() and its friends?

Workaround in the meantime:

any_of2 = function(x, ignore.case=TRUE, ...){
  matches(paste(paste0("^",x,"$"), collapse="|"), ignore.case=ignore.case, ...)
}
dplyr::select(iris, any_of2(c("sepal.length", "sepal.width"))) %>% names()
#> [1] "Sepal.Length" "Sepal.Width"

hmm I'm not sure this matches the spirit of these helpers because they are meant to be used in programmatic contexts where you need to be sure of the names of the columns you are targeting.

Well in my personal case, I'm confronted with a set of data frames from which I should select 2 columns that can or cannot exist, and when they exist they can be uppercase or lowercase.
This is because they can come from either R (lowercase) or SAS (uppercase).
Maybe this is a very specific case but I think many can relate, especially when datasets share a common structure but are implemented in different systems.

hmm I think in this case it's best to standardise the column names during the data cleaning step and use only one convention in the rest of the script. There is less chance of making a mistake and less mental overhead thinking about the data frames.