Learn R Programming

gtools (version 3.9.5)

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 = " "
)

Value

A character scalar containing the capitalized words.

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

Author

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

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").

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 https://www.quickanddirtytips.com/articles/capitalizing-titles/

See Also

chartr, taxize_capwords, capwords

Examples

Run this code

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 = "_")

Run the code above in your browser using DataLab