I'm looking to standardize some code which deals with cleaning data which has different column names over time. The idea is to create a dictionary along with a function which searches if a given dataset has names in the dictionary, and then replaces the names with the correct name (housed in the dictionary).
In the example below, 'Sepal.Length' would be converted to 'sepal_length'.
column_dict <- tibble(
from = c('Sepal.Length', 'length_of_sepal', 'sepal.lgth'),
to = c('sepal_length', 'sepal_length', 'sepal_length')
)
iris %>%
as_tibble %>%
map2(., column_dict, rename)