I'm struggling to use {tidyselect} for (what I think is) a simple pattern: I'd like to apply a transformation to any column who's name ends with "_id" or is named "id" itself. The input dataframes may or may not have columns meeting this requirement.
When only concerned with the "_id" requirement, it's easy:
df %>% mutate(
across(ends_with("_id"), myfun)
)
And if the table does include an "id" column, then this works, too:
df %>% mutate(
across(c("id", ends_with("_id")), myfun)
)
But the "id" column is sometimes-present-sometimes-missing. I can pretty easily solve for this with some basic conditionals and inspecting the colnames directly, but I was naïvely hoping this (any_of()) would work (it does not):
df %>% mutate(
across(any_of(c("id", ends_with("_id"))), myfun)
)
Is there a compact tidyselect version of this that I'm overlooking?