Combines utils_clean_names()
and tsl_names_set()
to help clean, abbreviate, capitalize, and add a suffix or a prefix to time series list names.
Usage
tsl_names_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
andprefix
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) Suffix for the clean names. Default: NULL.
- prefix
(optional, character string) Prefix for the clean names. Default: NULL.
See also
Other tsl_management:
tsl_colnames_clean()
,
tsl_colnames_get()
,
tsl_colnames_set()
,
tsl_count_NA()
,
tsl_diagnose()
,
tsl_handle_NA()
,
tsl_names_get()
,
tsl_names_set()
,
tsl_names_test()
,
tsl_ncol()
,
tsl_nrow()
,
tsl_repair()
,
tsl_split()
,
tsl_subset()
,
tsl_time()
,
tsl_time_class_set()
,
tsl_to_df()
Examples
#initialize time series list
tsl <- tsl_initialize(
x = fagus_dynamics,
name_column = "name",
time_column = "time"
)
#original names
tsl_names_get(
tsl = tsl
)
#> Germany Spain Sweden
#> "Germany" "Spain" "Sweden"
#abbreviate names
#---------------------------
tsl_clean <- tsl_names_clean(
tsl = tsl,
capitalize_first = TRUE,
length = 4 #abbreviate to 4 characters
)
#> distantia::zoo_name_set(): renaming zoo time series from 'Germany' to 'Grmn'.
#> distantia::zoo_name_set(): renaming zoo time series from 'Spain' to 'Span'.
#> distantia::zoo_name_set(): renaming zoo time series from 'Sweden' to 'Swdn'.
#new names
tsl_names_get(
tsl = tsl_clean
)
#> Grmn Span Swdn
#> "Grmn" "Span" "Swdn"
#suffix and prefix
#---------------------------
tsl_clean <- tsl_names_clean(
tsl = tsl,
capitalize_all = TRUE,
separator = "_",
suffix = "fagus",
prefix = "country"
)
#> distantia::zoo_name_set(): renaming zoo time series from 'Germany' to 'COUNTRY_GERMANY_FAGUS'.
#> distantia::zoo_name_set(): renaming zoo time series from 'Spain' to 'COUNTRY_SPAIN_FAGUS'.
#> distantia::zoo_name_set(): renaming zoo time series from 'Sweden' to 'COUNTRY_SWEDEN_FAGUS'.
#new names
tsl_names_get(
tsl = tsl_clean
)
#> COUNTRY_GERMANY_FAGUS COUNTRY_SPAIN_FAGUS COUNTRY_SWEDEN_FAGUS
#> "COUNTRY_GERMANY_FAGUS" "COUNTRY_SPAIN_FAGUS" "COUNTRY_SWEDEN_FAGUS"