View source: R/fix_tbl_names.R
fix_tbl_names | R Documentation |
Remove non-alphanum, replace whitespace with uscore, optionally lower, dedupe
fix_tbl_names(x, lower = TRUE, uniquify = TRUE)
x |
A character vector or a data.frame. If the latter, will extract names |
lower |
Lowercase the output? Defaults to |
uniquify |
should duplicate names be made unique? Defaults to |
This is a simple utility that replaces any non-alphanumeric characters in x with an
underscore, ensuring that runs of underscores > 1 are truncated to length 1, stripping any
trailing underscores, and optionally lowercasing the output (default TRUE
).
If uniquify=TRUE
(default), any duplicated values after the above are handled
via make.unique()
A character vector of cleaned-up names
x <- c("This is (a dirty) name with ", "A", "a") fix_tbl_names(x) fix_tbl_names(x, lower = FALSE) # by default, duplicate names are made unique xdf <- data.frame(1:10, LETTERS[1:10], letters[1:10]) names(xdf) <- x fix_tbl_names(xdf) # default fix_tbl_names(xdf, uniquify = FALSE) # allow duplicate names post-lowercase
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.