Learn R Programming

surveycore (version 0.8.3)

survey_metadata: Survey Metadata Container

Description

Stores variable labels, value labels, question prefaces, notes, and transformation history for variables in a survey design object. Automatically populated from haven-style attributes when as_survey() or related constructors are called.

Usage

survey_metadata(
  variable_labels = list(),
  value_labels = list(),
  question_prefaces = list(),
  notes = list(),
  universe = list(),
  missing_codes = list(),
  sata = list(),
  transformations = list(),
  weighting_history = list()
)

Value

A survey_metadata object.

Arguments

variable_labels

A named list mapping variable names to character labels (e.g., list(age = "Age in years")).

value_labels

A named list mapping variable names to named vectors of value labels (e.g., list(sex = c(Male = 1L, Female = 2L))).

question_prefaces

A named list mapping variable names to shared question battery preface text.

notes

A named list mapping variable names to analyst notes.

universe

A named list mapping variable names to universe descriptions (e.g., list(age = "Adults 18+")). Describes the population to which a variable applies.

missing_codes

A named list mapping variable names to atomic vectors of missing-value codes (e.g., list(age = c(Refused = 99L, DK = 98L))).

sata

A named list mapping variable names to TRUE for variables that are select-all-that-apply (SATA). Only variables explicitly marked as SATA appear in this list — absence means the variable is not SATA.

transformations

A named list tracking variable transformation history (populated automatically during operations).

weighting_history

A list recording weighting operations applied to the survey object (e.g., raking, trimming). Each entry is written by a surveywts function and contains the operation name, parameters, effective sample size before/after, and design effect. Always list() until a surveywts weighting function is applied. Reserved for Phase 2.5.

See Also

Other metadata: classify_question_type(), extract_metadata(), extract_missing_codes(), extract_question_preface(), extract_sata(), extract_universe(), extract_val_labels(), extract_var_label(), extract_var_note(), infer_question_prefaces(), set_missing_codes(), set_question_preface(), set_sata(), set_universe(), set_val_labels(), set_var_label(), set_var_note(), survey_weighting_history()

Examples

Run this code
# Empty metadata (default)
m <- survey_metadata()
m@variable_labels

# Pre-populated metadata
m <- survey_metadata(
  variable_labels = list(age = "Respondent age", income = "Annual income"),
  value_labels = list(sex = c(Male = 1L, Female = 2L))
)
m@variable_labels$age
m@value_labels$sex

Run the code above in your browser using DataLab