R/utils.cleanVarNames.R

Defines functions cleanVarNames

Documented in cleanVarNames

#' Title
#'
#' @param data
#' @param verbose
#' @param DEBUG
#' @param upper
#' @param forbiden.char
#' @param forbiden.last.char
#'
#' @return
#' @export
#'
#' @examples
cleanVarNames <- function(data, verbose=TRUE, DEBUG=FALSE, upper = TRUE,
                          forbiden.char = c(" ",".",":",";","-","__","(",")","[","]","{","}","$","%","&","/","\\","!"),
                          forbiden.last.char = c("_"," ")) {

  if(!is.data.frame(data)) stop("'data' is not a data.frame")

  var.names <- names(data)
  if(verbose) message("[cleanVarNames] Cleaning...")
  for(cont in seq_along(var.names)){
    if(DEBUG) message("Cleaning ",var.names[cont])
    var.names[cont] <- strClean(var.names[cont],
                                upper = upper, DEBUG = DEBUG,
                                forbiden.char = forbiden.char,
                                forbiden.last.char = forbiden.last.char)

  }

  names(data) <- var.names
  return(data)
}
feranpre/feR documentation built on Nov. 22, 2022, 2:29 a.m.