Skip to contents

This function splits strings formatted in camelCase or PascalCase into their component words. It can handle words where uppercase letters transition to lowercase letters, and it is capable of handling strings with sequences of uppercase letters followed by lowercase letters, effectively separating acronyms from camelCase beginnings.

Usage

splitCamel(x, conseq = TRUE)

splitPascal(x, conseq = TRUE)

Source

<stackoverflow.com/questions/8406974/splitting-camelcase-in-r>

Arguments

x

A character vector containing CamelCase or PascalCase strings to be split.

conseq

Logical indicating whether consecutive uppercase letters should be treated as part of the previous word (TRUE) or as separate words (FALSE). Default is TRUE.

Value

A list of character vectors, each containing the parts of the corresponding CamelCase or PascalCase string split at the appropriate transitions. If conseq is FALSE, acronyms followed by words are separated.

Examples

splitCamel("splitCamelCaseIntoWords")
#> [[1]]
#> [1] "split" "Camel" "Case"  "Into"  "Words"
#> 
splitCamel(c("fooBar", "FOOBar", "anotherFOOBarTest"), conseq = FALSE)
#> [[1]]
#> [1] "foo" "Bar"
#> 
#> [[2]]
#> [1] "F"   "O"   "O"   "Bar"
#> 
#> [[3]]
#> [1] "another" "F"       "O"       "O"       "Bar"     "Test"   
#>