Resulting strings are unique and consist only of the _
character, numbers, and letters.
Capitalization preferences can be specified using the case
parameter.
For use on the names of a data.frame, e.g., in a `%>%`
pipeline,
call the convenience function clean_names
.
Accented characters are transliterated to ASCII. For example, an "o" with a German umlaut over it becomes "o", and the Spanish character "enye" becomes "n".
make_clean_names(string, case = c("snake", "lower_camel", "upper_camel",
"screaming_snake", "lower_upper", "upper_lower", "all_caps",
"small_camel", "big_camel", "old_janitor", "parsed", "mixed", "none"))
A character vector of names to clean.
The desired target case (default is "snake"
), indicated by these possible values:
"snake"
produces snake_case
"lower_camel"
or "small_camel"
produces lowerCamel
"upper_camel"
or "big_camel"
produces UpperCamel
"screaming_snake"
or "all_caps"
produces ALL_CAPS
"lower_upper"
produces lowerUPPER
"upper_lower"
produces UPPERlower
old_janitor
: legacy compatibility option to preserve behavior of clean_names
prior to addition of the "case" argument(janitor versions <= 0.3.1 ). Provided as a quick fix for old scripts broken by the changes to clean_names
in janitor v1.0.
"parsed"
, "mixed"
, "none"
: less-common cases offered by snakecase::to_any_case
. See to_any_case
for details.
Returns the "cleaned" character vector.
# NOT RUN {
# cleaning the names of a vector:
x <- structure(1:3, names = c("name with space", "TwoWords", "total $ (2009)"))
x
names(x) <- make_clean_names(names(x))
x # now has cleaned names
# if you prefer camelCase variable names:
make_clean_names(names(x), "small_camel")
# similar to janitor::clean_names(poorly_named_df):
# not run:
# make_clean_names(names(poorly_named_df))
# }
Run the code above in your browser using DataLab