Skip to contents

This function attempts to split characters into its component words (and by default, all in lowercase) based on camelCase, PascalCase, or snake_case conventions. If the string doesn't match any of these conventions, it returns all groups of letters.

Usage

trySplitWords(..., conseq = TRUE, strictSnake = FALSE, uncase = TRUE)

Arguments

...

character(s) to be split, treated as a single vector after unlisting.

conseq

A logical indicating whether the conseq argument in splitCamel()/splitPascal() should be TRUE or FALSE.

strictSnake

A logical indicating the strict argument in isSnakeCase().

uncase

A logical indicating whether to remove all casing in the output to lowercase.

Value

A list of character vectors, each containing the parts of the string split into individual words.

Examples

trySplitWords("camelCaseExample")
#> [[1]]
#> [1] "camel"   "case"    "example"
#> 
trySplitWords("PascalCaseExample")
#> [[1]]
#> [1] "pascal"  "case"    "example"
#> 
trySplitWords(
    "snake_case_example", c("more_snake_cases"), "third_snake_case"
)
#> [[1]]
#> [1] "snake"   "case"    "example"
#> 
#> [[2]]
#> [1] "more"  "snake" "cases"
#> 
#> [[3]]
#> [1] "third" "snake" "case" 
#> 
trySplitWords("some|random|case")
#> [[1]]
#> [1] "some"   "random" "case"  
#> 
trySplitWords("Space Words", "UPPER_CASE", uncase = TRUE)
#> [[1]]
#> [1] "space" "words"
#> 
#> [[2]]
#> [1] "upper" "case" 
#>