clean_titles: Several options for formatting text into neater titles

Description Usage Arguments Details Value Examples

View source: R/clean_titles.R

Description

This function combines several ways titles and names may need to be formatted. It's meant to be simple, yet flexible.

Usage

1
2
3
4
5
6
7
8
clean_titles(
  x,
  cap_all = FALSE,
  split_case = TRUE,
  keep_running_caps = TRUE,
  space = "_",
  remove = NULL
)

Arguments

x

A character vector

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.

Details

Examples of possible common operations include:

Value

A character vector with each item newly formatted

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
t1 <- c("GreaterNewHaven", "greater_new_haven", "GREATER_NEW_HAVEN")
clean_titles(t1, cap_all = TRUE, keep_running_caps = FALSE)

t2 <- c("Male!CollegeGraduates", "Male CollegeGraduates")
clean_titles(t2, space = c("_", "!"))

t3 <- c("Greater BPT Men", "Greater BPT Men HBP", "GreaterBPT_men", "greaterBPT")
clean_titles(t3, cap_all = FALSE)

t4 <- c("New Haven town, New Haven County, Connecticut",
        "Newtown town, Fairfield County, Connecticut")
clean_titles(t4, cap_all = TRUE, remove = " town,.+")

camille-s/camiller documentation built on Jan. 22, 2022, 6:50 a.m.