R/capwords.r

capwords <- function(s, strict = FALSE, sentence=T) {
	cap <- function(s) paste(toupper(substring(s, 1, 1)),
                       {s <- substring(s, 2); if(strict) tolower(s) else s},
                                  sep = "", collapse = " " )
	if(sentence){
		sapply(s, cap, USE.NAMES = !is.null(names(s)))
	} else {
		sapply(strsplit(s, split = " "), cap, USE.NAMES = !is.null(names(s)))
	}
}
jae0/stmenv documentation built on May 28, 2019, 11 p.m.