Skip to contents

This is a collection of a few functions for common string transformations.

Usage

title_case(x, lower = NULL)

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.

Value

A character vector

Details

title_case is a wrapper around stringr::str_to_title, 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).

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") # This result is technically
#> [1] "Rates Are Going up in the Area"
# incorrect--"up" is used as an adverb here, and under APA should be
# capitalized. Write this one out manually.