Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

capwords

Capitalize Words for Titles


Description

This function capitalizes words for use in titles

Usage

capwords(s, strict=FALSE, AP=TRUE, onlyfirst=FALSE,
         preserveMixed=FALSE, sep=" ")

Arguments

s

character string to be processed

strict

Logical, remove all additional capitalization.

AP

Logical, apply the Associated Press (AP) rules for prepositions and conjunctions that should not be capitalized in titles.

onlyfirst

Logical, only capitalize the first word.

preserveMixed

Logical, preserve the capitalization mixed-case words containing an upper-case letter after a lower-case letter.

sep

Character string, word separator

Details

This function separates the provided character string into separate words using sep as the word separator. If firstonly==TRUE, it then capitalizes the first letter the first word, otherwise (the default), it capitalizes the first letter of every word. If AP==TRUE, it then un-capitalizes words in the Associated Press's (AP) list of prepositions and conjunctions should not be capitalized in titles. Next, it capitalizes the first word. It then re-joins the words using the specified separator.

If preserveMixed==TRUE, words with an upper-case letter appearing after a lower-case letter will not be changed (e.g. "iDevice").

Value

A character scalar containing the capitalized words.

Author(s)

Gregory R. Warnes greg@warnes.net based on code from the chartr manual page, and taxize_capwords in the taxize package.

References

Fogarty, Mignon. Capitalizing Titles: "Which words should you capitalize? Grammar Girl's Quick and Dirty Tips for Better Writing. 9 Jun. 2011. Quick and Dirty Tips Website." Accessed 22 April 2016 http://www.quickanddirtytips.com/education/grammar/capitalizing-titles

See Also

Examples

capwords("a function to capitalize words in a title")
capwords("a function to capitalize words in a title", AP=FALSE)

capwords("testing the iProduct for defects")
capwords("testing the iProduct for defects", strict=TRUE)
capwords("testing the iProduct for defects", onlyfirst=TRUE)
capwords("testing the iProduct for defects", preserveMixed=TRUE)

capwords("title_using_underscores_as_separators", sep="_")

gtools

Various R Programming Tools

v3.8.2
GPL-2
Authors
Gregory R. Warnes, Ben Bolker, and Thomas Lumley
Initial release
2020-03-23

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.