R/capIt.r

Defines functions capIt

Documented in capIt

#' Capitalize first letter of a string
#'
#' Capitalize the first letter of a string or the first letters of a list of strings.
#'
#' @param x Character or character vector.
#' @return Character or character vector.
#' @seealso \code{\link{toupper}}, \code{\link{tolower}}, 
#' @examples
#' x <- c('shots', 'were', 'exchanged at the ', 'hospital.')
#' capIt(x)
#' @export

capIt <- function(x) {

    capWorker <- function(x) {
        s <- strsplit(x, ' ')[[1]]
        paste(toupper(substring(s, 1,1)), substring(s, 2),
              sep='', collapse=' ')
    }

    sapply(x, capWorker)
}

Try the omnibus package in your browser

Any scripts or data that you put into this service are public.

omnibus documentation built on Sept. 17, 2024, 5:09 p.m.