case: Letter case

View source: R/utils2.R

caseR Documentation

Letter case

Description

Convert a text string to several common cases.

Usage

case(
  x,
  case = c("first", "upcase", "downcase", "camelcase", "upper", "lower", "lowup",
    "uplow"),
  translate = FALSE
)

Arguments

x

a text string

case

a case to use; can be (unambiguously) abbreviated; see details

translate

logical; if TRUE, strings will be translated to upper- or lowercase before case is applied to ensure that the case of all characters of x is uniform

Details

This function supports the following letter cases:

first Only the first letter is uppercase
upcase Each Word Is Uppercase
downcase tHE oPPOSITE oF uPCASE
camelcase TheStringWillBeInCamelCase
upper EQUIVALENT TO toupper
lower equivalent to tolower
lowup aLtErNaTiNg cAsEs
uplow ThE OpPoSiTe oF LoWuP

Examples

cases <- eval(formals(case)$case)
x <- 'the quick brown fox'
sapply(cases, case, x = x)

## all cases are vectorized
sapply(cases, case, x = strsplit(x, ' ')[[1]])

case('upCASE', 'upcase', translate = FALSE) ## default
case('upCASE', 'upcase', translate = TRUE)


raredd/rawr documentation built on March 4, 2024, 1:36 a.m.