Fix character variables by removing extraneous whitespace and possibly changing capitalization.

When using title case, words starting after an "-" are capitalized. A letter preceding an apostrophe (') is not capitalized. The words "and", "the" and "of" are not capitalized. Single letters alternated with dots (abbreviations) are capitalized.

Alternatively, you can get title case with tools::toTitleCase(fix_name(x, "lower"))

fix_name(x, case="", skip="", lowothers=TRUE)

Arguments

x

character

case

character. If this is not "", the capitalization of the words is changed. You can use "first", "lower", or "title"

skip

character. Additional words to skip when case="title" (see details)

lowothers

logical. Only relevant when case is "first" or "title". Should all other characters be made lowercase?

Value

character

Examples

d <- c("aruba", "BOM BINI", "saint-vincent and the grenadines",
       "the u.s. of america", "côte d'ivoire")
fix_name(d, "title")
#> [1] "Aruba"                            "Bom Bini"                        
#> [3] "Saint-Vincent and the Grenadines" "the U.S. of America"             
#> [5] "Côte d'Ivoire"                   
fix_name(d, "title", skip="bini")
#> [1] "Aruba"                            "Bom bini"                        
#> [3] "Saint-Vincent and the Grenadines" "the U.S. of America"             
#> [5] "Côte d'Ivoire"