Skip to content
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

Graceful partial matching for column renaming #561

Open
D3SL opened this issue Apr 17, 2024 · 1 comment
Open

Graceful partial matching for column renaming #561

D3SL opened this issue Apr 17, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@D3SL
Copy link

D3SL commented Apr 17, 2024

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") 
}
@SebKrantz
Copy link
Owner

SebKrantz commented Apr 18, 2024

Thanks. I will consider adding this, though through an extra argument as collapse does not support tidyselect expressions.

@SebKrantz SebKrantz added the enhancement New feature or request label Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants