tsl_colnames_clean: Clean Column Names in Time Series Lists

View source: R/tsl_colnames.R

tsl_colnames_cleanR Documentation

Clean Column Names in Time Series Lists

Description

Uses the function utils_clean_names() to simplify and normalize messy column names in a time series list.

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 capitalize_first = TRUE, the first letter is capitalized.

  • If capitalize_all = TRUE, all letters are capitalized.

  • If argument length is provided, base::abbreviate() is used to abbreviate the new column names.

  • If suffix is provided, it is added at the end of the column name using the separator.

  • If prefix is provided, it is added at the beginning of the column name using the separator.

Usage

tsl_colnames_clean(
  tsl = NULL,
  lowercase = FALSE,
  separator = "_",
  capitalize_first = FALSE,
  capitalize_all = FALSE,
  length = NULL,
  suffix = NULL,
  prefix = NULL
)

Arguments

tsl

(required, list) Time series list. 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. Also used to separate suffix and prefix from 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 column names. Default: NULL.

prefix

(optional, character string) String to prepend to the column names. Default: NULL.

Value

time series list

See Also

Other tsl_management: tsl_burst(), tsl_colnames_get(), tsl_colnames_prefix(), tsl_colnames_set(), tsl_colnames_suffix(), tsl_count_NA(), tsl_diagnose(), tsl_handle_NA(), tsl_join(), tsl_names_clean(), tsl_names_get(), tsl_names_set(), tsl_names_test(), tsl_ncol(), tsl_nrow(), tsl_repair(), tsl_subset(), tsl_time(), tsl_to_df()

Examples

#generate example data
tsl <- tsl_simulate(cols = 3)

#list all column names
tsl_colnames_get(
  tsl = tsl
)

#rename columns
tsl <- tsl_colnames_set(
  tsl = tsl,
  names = c(
  "New name 1",
  "new Name 2",
  "NEW NAME 3"
  )
)

#check new names
tsl_colnames_get(
  tsl = tsl,
  names = "all"
)

#clean names
tsl <- tsl_colnames_clean(
  tsl = tsl
)

tsl_colnames_get(
  tsl = tsl
)

#abbreviated
tsl <- tsl_colnames_clean(
  tsl = tsl,
  capitalize_first = TRUE,
  length = 6,
  suffix = "clean"
)

tsl_colnames_get(
  tsl = tsl
)

distantia documentation built on April 4, 2025, 5:42 a.m.