ProcessNames: ProcessNames

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/aveytoolkit_ProcessNames.R

Description

Cleans up strings to make them pretty names by removing punctuation, whitespace, and specified substrings

Usage

1
ProcessNames(strs, stringsToRm = NULL, rmPunct = TRUE, sep = "_")

Arguments

strs

vector or strings to process

stringsToRm

a vector or list of strings to search for and remove from strs

rmPunct

should punctuation be removed? Default is TRUE.

sep

character to replace whitespace

Details

stringsToRm are replaced by ” in the order they are given using gsub. After this, punctuation is removed if rmPunct is TRUE. Then, leading and/or trailing whitespace will be removed and the sep will be used to separate words. This function is useful when reading in other people's data and you want to change the row or column names to legal R names or just shorten the names.

Value

a vector of modified strings from strs

Author(s)

Stefan Avey

See Also

gsub

Examples

1
2
3
4
5
6
7
badNames <- c("Who's Birthday?", "[Date]", "gift Received")
## Remove the string "Who's", remove punctuation, and separate words by '_'
goodNames <- ProcessNames(badNames,stringsToRm="Who's", rmPunct=TRUE, sep='_')
goodNames
## Remove the string "Who's", don't remove punctuation, and put no separation between words
goodNames <- ProcessNames(badNames,stringsToRm="Who's", rmPunct=FALSE, sep='')
goodNames                          

stefanavey/aveytoolkit documentation built on March 5, 2020, 12:49 a.m.