Clean and format character vectors for use as column names or variable names.
Usage
utils_clean_names(
  x = NULL,
  lowercase = FALSE,
  separator = "_",
  capitalize_first = FALSE,
  capitalize_all = FALSE,
  length = NULL,
  suffix = NULL,
  prefix = NULL
)Arguments
- x
- (required, character vector) Names to be cleaned. Default: NULL 
- lowercase
- (optional, logical) If TRUE, all names are coerced to lowercase. Default: FALSE 
- separator
- (optional, character string) Separator when replacing spaces and dots and appending - suffixand- prefixto the main word. Default: "_".
- capitalize_first
- (optional, logical) Indicates whether to capitalize the first letter of each name Default: FALSE. 
- capitalize_all
- (optional, logical) Indicates whether to capitalize all letters of each name Default: FALSE. 
- length
- (optional, integer) Minimum length of abbreviated names. Names are abbreviated via - abbreviate(). Default: NULL.
- suffix
- (optional, character string) String to append to the cleaned names. Default: NULL. 
- prefix
- (optional, character string) String to prepend to the cleaned names. Default: NULL. 
Details
The cleanup operations are applied in the following order:
- Remove leading and trailing whitespaces. 
- Generates syntactically valid names with - base::make.names().
- Replaces dots and spaces with the - separator.
- Coerces names to lowercase. 
- If argument - lengthis provided,- base::abbreviate()is used to abbreviate the new column names.
- If - suffixis provided, it is added at the end of the column name using the separator.
- If - prefixis provided, it is added at the beginning of the column name using the separator.
- If - capitalize_first = TRUE, the first letter is capitalized.
- If - capitalize_all = TRUE, all letters are capitalized.
See also
Other internal:
utils_boxplot_common(),
utils_check_args_distantia(),
utils_check_args_matrix(),
utils_check_args_momentum(),
utils_check_args_path(),
utils_check_args_tsl(),
utils_check_args_zoo(),
utils_check_distance_args(),
utils_check_list_class(),
utils_digits(),
utils_distantia_df_split(),
utils_prepare_df(),
utils_prepare_matrix(),
utils_prepare_matrix_list(),
utils_prepare_time(),
utils_prepare_vector_list(),
utils_prepare_zoo_list(),
utils_tsl_pairs()
Examples
x <- c(
  "GerMany",
  "spain",
  "SWEDEN"
)
#abbreviate names
#---------------------------
#abbreviate to 4 characters
utils_clean_names(
  x = x,
  capitalize_all = TRUE,
  length = 4
)
#> GerMany   spain  SWEDEN 
#>  "GRMN"  "SPAN"  "SWED" 
#suffix and prefix
#---------------------------
utils_clean_names(
  x = x,
  capitalize_first = TRUE,
  separator = "_",
  prefix = "my_prefix",
  suffix = "my_suffix"
)
#>                       GerMany                         spain 
#> "My_prefix_GerMany_my_suffix"   "My_prefix_spain_my_suffix" 
#>                        SWEDEN 
#>  "My_prefix_SWEDEN_my_suffix" 
