Format character strings to use snake-style formatting, where word boundaries are defined by underscores (e.g. this_is_snake_case).

snakeCase(object, ...)

# S4 method for character
snakeCase(
  object,
  rename = FALSE,
  recursive = FALSE,
  smart = TRUE,
  names = !rename,
  prefix = !rename
)

snake(...)

Arguments

object

Object.

...

Additional arguments.

rename

logical(1). File rename mode. Requires that input contains files and/or directories that exist on disk. Both case-sensitive (e.g. Linux) and -insensitive (e.g. macOS, Winddows) file systems are supported.

The prefix and smart arguments are supported in this mode.

recursive

logical(1). Should the function recurse into directories? Only applicable when rename = TRUE.

smart

logical(1). Handle complicated special cases, such as mixed case acronyms, plus/minus, percentages, etc.

names

logical(1). Sanitize names.

Only applies to string mode (rename = FALSE).

prefix

logical(1). Prepend "X" character if necessary, when string begins with a syntactically invalid character, such as a number or non-alphanumeric. Note that names are always made syntactically valid when applicable with "X" prefix. See make.names() for details.

Enabled by default for string mode, but disabled by default for rename mode, when applicable.

Value

Modified object. Contains syntatically valid names. For objects supporting names(), the underlying data returns unchanged, except for character or vector class. Returns invisible modified file path when rename = TRUE. Returns invisible NULL when recursive = TRUE.

Note

Updated 2019-12-05.

Examples

data(syntactic, package = "acidtest") object <- syntactic$character snakeCase(object)
#> [1] "percent_gc" "x10um" "x5_3_bias" #> [4] "x5prime" "g2m_score" "hello_world" #> [7] "hello_world" "mazda_rx4" "n_count" #> [10] "rnai_clones" "tx2gene" "tx2_gene_id" #> [13] "worfdb_html_remap" "x123"