A vectorized companion to get_label. Returns a named character
vector of labels for one or more variable names, making it convenient to
label axes, table columns, or multi-panel plots in a single call.
Variables not found in the label map cause an error (just like
get_label), so typos are caught immediately.
Arguments
- label_map_df
A data frame with
keyandlabelcolumns, as returned bylabel_map.- variables
A character vector of variable names to look up.
Value
A named character vector with names equal to variables
and values equal to the corresponding labels.
Examples
dta <- generate_survival_data(n = 50, seed = 42)
lmap <- label_map(dta)
# Look up several labels at once
get_labels(lmap, c("age", "bmi", "hgb_bs"))
#> age bmi
#> "Age at surgery (years)" "Body mass index (kg/m2)"
#> hgb_bs
#> "Baseline hemoglobin (g/dL)"
# Useful for table column headers
vars <- c("age", "bmi", "lvefvs_b")
headers <- get_labels(lmap, vars)
print(headers)
#> age bmi
#> "Age at surgery (years)" "Body mass index (kg/m2)"
#> lvefvs_b
#> "Baseline LV ejection fraction (%)"