#' @import magrittr
#' @importFrom Hmisc capitalize
NULL
#' Changes names to more attractive format
#'
#' Changes colnames (names if vector) to more attractive format
#' @param character vector or data.frame
#' @return object with nicer names
#' @example
#' x <- data.frame(country_ISO3=c('PL','RU','US'), accounts_number = c(1500,1000,1200))
#' x %>% prettyNames
#' @export
prettyNames <- function(object, names=T){
if(names==F){
object <- gsub("[[:space:][:punct:]]*$","", x=object)
object <- gsub("_|[ ]{2,100}"," ", x=object)
object <- capitalize(object)
} else if('data.frame' %in% class(object) & names){
colnames(object) %<>% gsub("^l_|^v_|^g","", x=.)
colnames(object) %<>% gsub("_rd1m|_rd1y","", x=.)
colnames(object) %<>% gsub("_cm$|_cy$","", x=.)
colnames(object) %<>% gsub("_"," ", x=.) %>% capitalize()
} else if (class(object) %in% c('series','list')) {
names(object) %<>% gsub("[[:space:]]+$","", x=.) %>%
gsub("[[:punct:]]+$","", x=.) %>%
gsub("_|[ ]+"," ", x=.) %>%
capitalize()
} else {
object %<>% setNames(gsub("_"," ", x=capitalize(.)))
}
return(object)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.