darwin-eu-dev / omopgenerics

https://darwin-eu-dev.github.io/omopgenerics/
Apache License 2.0
2 stars 1 forks source link

Utility function to warn if variables already exists: validateExisitingVariable() #467

Open edward-burn opened 1 month ago

edward-burn commented 1 month ago

When functions create new variables we often need to check whether the variable already exists and warn that it will be overwritten. A utility function that by default 1) produces a warning that the variable exists and 2) drops the existing variable (to avoid any possible problems with joins etc). We could also include the option that instead of warning + drop, instead an error is returned

https://pharmaverse.github.io/admiraldev/dev/reference/warn_if_vars_exist.html

edward-burn commented 1 month ago

We could also include here, or as a separate function, the opposite - when we want specific variables to exist (e.g if the user gives a variable name that they want to stratify by)

catalamarti commented 3 weeks ago

x <- dplyr::tibble(a = 1, b = 1, x = 1)

x <- validateExitingColumn(x, "z") # both x would be identical
x <- validateExitingColumn(x, "a") # that would return a warning + remove the column a