R/cleanup_headers.R

Defines functions cleanup_headers

Documented in cleanup_headers

#' Transform vector into strings that can be headers in a data.frame
#' @export
#' @param x Character vector of column names
#' @examples 
#' column_names <- c("MRN ID", "First & Middle Name", "Name: Last")
#' 
#' cleanup_headers(column_names)
cleanup_headers <- function(x) {

  x <- trimws(x)
  x <- gsub("&", "and", x)
  x <- gsub("\\s", "_", x)
  x <- gsub("\\/", "_", x)
  x <- gsub("-|\\.", "_", x)
  x <- gsub(";|:", "_", x)
  x <- gsub("\\(|\\)", "_", x)
  x[grepl("^\\d", x)] <- paste0("X", x[grepl("^\\d", x)])
  x <- gsub("_{2,}", "_", x)

  x
}
NateByers/IUHhelpers documentation built on Feb. 25, 2020, 8:43 p.m.