(Somewhat related question: Enter new column names as string in dplyr's rename function)
In the middle of a dplyr chain (%>%), I wou
In case you don't want to write the regular expressions yourself, you could use
janitor::make_clean_names() which has some nice defaults orjanitor::clean_names() which does the same as make_clean_names(), but works directly on data frames.Invoking them inside of a pipeline should be straightforward.
library(magrittr)
library(snakecase)
iris %>% setNames(to_snake_case(names(.)))
iris %>% tibble::as_tibble(.name_repair = to_snake_case)
iris %>% purrr::set_names(to_snake_case)
iris %>% dplyr::rename_all(to_snake_case)
iris %>% janitor::clean_names()