capitalize: Capitalize initial characters in strings of text 'x'.

View source: R/text_fun.R

capitalizeR Documentation

Capitalize initial characters in strings of text x.

Description

capitalize converts the case of each element's (i.e., character string or word in text) n initial characters to upper or lowercase.

Usage

capitalize(x, n = 1, upper = TRUE, as_text = FALSE)

Arguments

x

A string of text (required).

n

Number of initial characters to convert. Default: n = 1.

upper

Convert to uppercase? Default: upper = TRUE.

as_text

Treat and return x as a text (i.e., one character string)? Default: as_text = FALSE.

Details

If as_text = TRUE, the input x is merged into one string of text and the arguments are applied to each word.

Value

A character vector.

See Also

caseflip for converting the case of all letters; words_to_text and text_to_words for converting character vectors and texts.

Other text objects and functions: Umlaut, caseflip(), cclass, chars_to_text(), collapse_chars(), count_chars_words(), count_chars(), count_words(), invert_rules(), l33t_rul35, map_text_chars(), map_text_coord(), map_text_regex(), metachar, read_ascii(), text_to_chars(), text_to_sentences(), text_to_words(), transl33t(), words_to_text()

Examples

x <- c("Hello world!", "this is a TEST sentence.", "the end.")
capitalize(x)
capitalize(tolower(x))

# Options: 
capitalize(x, n = 3)                  # leaves strings intact
capitalize(x, n = 3, as_text = TRUE)  # treats strings as text
capitalize(x, n = 3, upper = FALSE)   # first n in lowercase


ds4psy documentation built on Sept. 15, 2023, 9:08 a.m.