Skip to content

Graceful partial matching for column renaming #561

@D3SL

Description

@D3SL

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") 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions