Skip to contents

Remove letter accents; replace spaces with periods; make all names lowercase; remove periods if they separate single characters

Usage

clean_string(
  x,
  accents = TRUE,
  spaces = TRUE,
  lowercase = TRUE,
  excess.periods = TRUE
)

Arguments

x

Character string

accents

Should accents be removed? Default = TRUE

spaces

Should spaces be removed? Default = TRUE

lowercase

Should all letters all be lowercase? Default = TRUE

excess.periods

Should excess periods be removed? Default = TRUE

Examples

fake<-c('    SOme DATA  here ','Données','n e b','A.S.O','.cfvn','ac.kg.tow','gh..kg.tow')
clean_string(fake)
#> [1] "some.data.here" "donnees"        "neb"            "aso"           
#> [5] "cfvn"           "ac.kg.tow"      "gh.kg.tow"     
clean_string(fake,accents=FALSE)
#> [1] "some.data.here" "données"        "neb"            "aso"           
#> [5] "cfvn"           "ac.kg.tow"      "gh.kg.tow"     
clean_string(fake,spaces=FALSE)
#> [1] "    some data  here " "donnees"              "n e b"               
#> [4] "aso"                  "cfvn"                 "ac.kg.tow"           
#> [7] "gh.kg.tow"           
clean_string(fake,lowercase=FALSE)
#> [1] "SOme.DATA.here" "Donnees"        "neb"            "ASO"           
#> [5] "cfvn"           "ac.kg.tow"      "gh.kg.tow"     
clean_string(fake,excess.periods=FALSE)
#> [1] "some.data.here" "donnees"        "n.e.b"          "a.s.o"         
#> [5] ".cfvn"          "ac.kg.tow"      "gh..kg.tow"