R/xlCap.R

Defines functions xlCap

Documented in xlCap

#' Capitalising words
#'
#' A sophisticated version of word capitalisation
#'
#' @param s the string to convert.
#' @param strict logical, if \code{True} then all words will have only
#' the first letter capitalised and others in lower cases.
#'
#' @export
xlCap <- function(s, strict = FALSE) {
  cap <- function(s) paste(toupper(substring(s, 1, 1)),
                           {s <- substring(s, 2); if(strict) tolower(s) else s},
                           sep = "", collapse = " " )
  sapply(strsplit(s, split = " "), cap, USE.NAMES = !is.null(names(s)))
}
xinye1/xltools documentation built on Dec. 2, 2020, 7:23 p.m.