Skip to contents

Adds human-readable value labels to a variable in a data.table using the PUMS codebook. Use for reporting, QA, or making tables more interpretable.

Usage

append_var_lab(dt, var, settings)

Arguments

dt

data.table with required columns:

  • <integer/numeric/character> — variable to label Rows: one per record. Keys: none required. Modified by reference: no (returns copy).

var

character(1). Name of variable to label (must exist in dt).

settings

list. Must include:

  • codebook_path — path to PUMS codebook

Value

data.table. Original data with an added _label column (factor).

Details

  • Reads value labels from the PUMS codebook using project settings.

  • Merges labels onto the specified variable, matching by value.

  • Adds a new column named _label with factor labels.

  • Returns a copy; does not modify by reference.

Settings

  • codebook_path (direct): Path to PUMS codebook. Default from config/settings.json.

Examples

## Not run:
# dt <- data.table(AGEP = c(18, 25, 40))
# settings <- ... # pipeline settings
# dt_labeled <- append_var_lab(dt, "AGEP", settings)
## End(Not run)