convert_strings: Convert string or column name separators and casings.

Description Usage Arguments Details Value

Description

Takes a string vector and converts the strings to use the specified separator and casing style.

Usage

1
2
3
convert_strings(source_strings, source_sep = NULL, ignore = NULL,
  target_sep = "_", target_case = "all_lower", special_caps = NULL,
  break_alpha_blocks = FALSE)

Arguments

source_strings

A string vector with one or more strings to convert. Non-character types will be forced to character with a warning.

source_sep

An optional character string specifying the character(s) or pattern(s) used as as separator in the source strings. The splitting is handled by strplit and so can be a regular expression. If the source style is a camel style or varies by string, it is suggested that you leave this blank as this will be detected automatically.

ignore

Only used if the source separator is auto-detected (i.e., source_sep is not specified). A vector of strings describing symbols to exclude as candidates.

target_sep

A character string describing the character(s) to be used as a separator in the converted strings. Defaults to an underscore ("_"). If target_case is set to either lower_camel or upper_camel, this value is ignored.

target_case

The casing style to be applied to the converted strings. Casing-only options include: all_lower, first_lower_then_upper, first_upper, all_upper, title, sentence. Casing + separator options include: lower_camel, upper_camel.

special_caps

An optional string vector of words that should be capitalized as specified in the string vector. They will be converted to lowercase for matching and matching words will be updated to match the version provided in the string vector.

break_alpha_blocks

If TRUE, conversion from camel case will break up capitalized blocks of letters to treat each letter as a single word. If FALSE (the default behavior), conversion will try to honor alpha blocks of three or more characters as single words. Where two capitalized characters occur together, they will be broken up unless they occur at the end of the string.

Details

Alternatively takes a dataframe and converts the column names to use the specified separator and casing style.

If a source separator style is not given (the default behavior), the function will attempt to identify what - if any - character or character set is used as a separator for each string.

Based on the given or identified source separator, the string is then broken up and converted to the target separator and casing style.

The function also takes additional arguments that give more fine-grained control over the conversion. You are able to manually specify characters the separator auto-detect should ignore and can provide more specific capitalization rules for target words in the strings.

Note: Blocks of numeric characters will be treated as distinct words when converting from camel case (e.g., in "omgPuppy120", "120" would be treated as a distinct word). Blocks of capitals longer than two characters will be treated likewise (e.g., in "omgIPuppyAAA", "AAA" would be treated as one word but "I" and "Puppy" separated) unless break_alpha_blocks = TRUE.

Value

If the input is a string vector - or is successfully converted - and the source separator is given - or can be auto-detected - the output will be a string_vector using the separator and casing style specified in target_sep and target_case.

If the input is a dataframe, a dataframe will be returned with the separator/case styling applied to the dataframe column names.


bwaismeyer/caser documentation built on May 13, 2019, 9:05 a.m.