For data preprocessing in a data project I need to transform some values based on a changing condition. I'd like to make a function that uses a boolean returning function named condition
and a list of vars.
my_function <- function(data, condition, list_of_vars) {
mutate(
data,
across(list_of_vars, ifelse(condition, a_value, alternative)
)
}
It seems like it should have something to do with quosures and maybe the {{ vars }}
operator, something along the lines of:
my_function <- function(data, condition, list_of_vars) {
mutate(
data,
across({{ list_of_vars }}, ifelse(condition, a_value, alternative)
)
}
How can I pass list of vars in which some change take place?