Regex support in get_vars() trivializes dealing with optional columns, but there's no equivalent to renaming afaik other than strings of if blocks. An option to ignore missing columns while renaming would mimic tidyselect's any_of and replace a great deal of boilerplate and repeated code.
eg:
library(tidyverse)
library(collapse)
sample<-data.frame(
foo="foo",
bar="bar",
foobar="foobar"
)
sample<-sample |> rename(any_of(c(both="foobar",both="foo_bar")))
##contrast with
if("foobar" %chin% names(sample)){
sample<-sample |> frename(both="foobar")
}
if("foo_bar" %chin% names(sample)){
sample<-sample |> frename(both="foo_bar")
}
Regex support in
get_vars()trivializes dealing with optional columns, but there's no equivalent to renaming afaik other than strings ofifblocks. An option to ignore missing columns while renaming would mimic tidyselect'sany_ofand replace a great deal of boilerplate and repeated code.eg: