Skip to contents

Adds human-readable labels for targets and categories to a summary table, using settings definitions and update mappings. Handles compound levels and range categories, and allows for custom/combined categories defined in settings$target_updates.

The function works as follows:

  1. Parses the target string into target name and level (category).

  2. Looks up human-readable labels for the target and for the category, using:

    • (a) The update_map, if provided and relevant for the target/level;

    • (b) The main settings (levels/label_levels);

    • (c) If the target is numeric, uses a helper for range-matching;

  3. Returns the input data frame with columns "Target_Label" (target variable label) and "Category_Label" (category label or range).

Usage

label_targets(df, settings, update_map = NULL)

Arguments

df

Data frame or data.table. Must have a column "Target" with target/level strings.

settings

List of settings, typically parsed from YAML, including elements targets and target_updates.

update_map

(Optional) List as built by build_update_map. If NULL, will be built internally from settings.

Value

Data frame with added columns "Target_Label" and "Category_Label".

Examples

# df should have a column "Target" with values like "p_age_18_34"
# settings should be as parsed from YAML
# result <- label_targets(df, settings)