convert_string: Convert the separator/casing for a single string.

Description Usage Arguments Details Value

Description

Takes a single string and converts it so that it uses the desiginated separator and casing style.

Usage

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

Arguments

source_str

A character string to convert to a new separator and/or casing style. Non-character types will be forced to character with a warning.

source_sep

An optional character string specifying the character(s) or pattern used as as separator in the source string. The splitting is handled by strplit and so can be a regular expression. If the source style is a camel style, 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 string. 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 string. 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

This function implements the core behavior of the package for a single string - it is not vectorized and is not intended for external use. It takes an optional argument allowing the user to specify a source separator style.

If a source separator style is not given, it will attempt to identify what - if any - character is used as a separator.

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

Value

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


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