Skip to contents

This function is a wrapper around clean_titles() which corrects for the fact that not all words in a title should be capitalized (articles, prepositions, etc. not at the beginning of the title). It follows the APA style guide the best I could, but there may be exceptions to fix manually (see examples).

Usage

title_case(x, lower = NULL, clean = TRUE, ...)

Arguments

x

A character vector to alter

lower

Aside from a built-in list of articles and prepositions, any additional words that should be kept lowercase.

clean

Boolean: if TRUE (the default), strings will be passed to clean_titles as an intermediate step, mostly to break snakecased text into words before converting to title casing.

...

Arguments passed on to clean_titles

cap_all

Logical: if TRUE, first letter of each word after splitting will be capitalized. If FALSE, only the first character of the string will be capitalized. Note that in order to balance this with respecting consecutive capital letters, such as from acronyms,

split_case

Logical: if TRUE, consecutive lowercase-uppercase pairs will be treated as two words to be separated.

keep_running_caps

Logical: if TRUE, consecutive uppercase letters will be kept uppercase.

space

Character vector of characters and/or regex patterns that should be replaced with a space to separate words.

remove

Character vector of characters and/or regex patterns that will be removed before any other operations; if NULL, nothing is removed.

Value

A character vector

See also

Examples

title_case(c("rates are rising in the area", "of all adults in the region"))
#> [1] "Rates Are Rising in the Area" "Of All Adults in the Region" 
title_case("rates are going up in the area")
#> [1] "Rates Are Going up in the Area"
# This result is technically incorrect--"up" is used as an adverb here, and 
# under APA should be capitalized. Write this one out manually.