Use a yspec object to convert a vector of column names to the short name with the unit optionally appended.

ys_recode(col, spec, ..., unit = FALSE)

Arguments

col

A character vector of names in spec.

spec

A yspec object.

...

Passed to ys_get_short() (when unit is FALSE) or ys_get_short_unit() (when unit is TRUE); specifically note that title_case and short_max can be passed along.

unit

Logical indicating if the unit should be appended to the short name.

Examples

spec <- ys_help$spec()

x <- c("WT", "BAR", "SCR", "TIME", "FOO")

ys_recode(x, spec)
#> [1] "weight"           "BAR"              "serum creatinine" "TIME"            
#> [5] "FOO"             

ys_recode(x, ys_select(spec, -TIME), unit = TRUE, title_case = TRUE)
#> [1] "Weight (kg)"              "BAR"                     
#> [3] "Serum Creatinine (mg/dL)" "TIME"                    
#> [5] "FOO"