Skip to contents

Sets a per-variable extension-slot payload — a flat, pass-through named list that surveycore stores and returns unchanged. surveycore never reads, validates, or acts on the payload's values; it confirms only that the top-level value is a list or NULL, and that a non-empty list's top-level names are present, non-empty, and unique.

Usage

set_var_extra(x, ..., variable = NULL, extra = NULL)

Arguments

x

A survey design object or a data frame.

...

Named arguments where the name is the variable and the value is the extension payload (a list, or NULL to clear it). Supports !!! list splicing.

variable

A character vector of variable names. Use with extra.

extra

A list of payloads, one element per entry of variable, in the same order. Each element must itself be a list or NULL.

Value

The modified object, invisibly.

Details

Supports Conventions 1, 2, and 3 — see set_var_label() for details on the calling conventions. Unlike set_missing_codes(), there is no bare-payload shorthand for Convention 3 with a single variable: a bare named list cannot be distinguished from a one-element outer list, so the payload must be wrapped in an outer list (extra = list(list(role = "demographic"))). Passing an un-wrapped named list of length 1 raises surveycore_error_var_extra_ambiguous_wrap.

Examples

d <- as_survey(
  gss_2024,
  ids = vpsu,
  weights = wtssps,
  strata = vstrat,
  nest = TRUE
)
d <- set_var_extra(d, age = list(role = "demographic"))
extract_var_extra(d, age)
#> $age
#> $age$role
#> [1] "demographic"
#> 
#>