Skip to contents

Returns the extension-slot payload for one or more variables in a survey design object or data frame. Read-only; performs no validation of payload contents — values are returned exactly as stored, never coerced.

Usage

extract_var_extra(x, ..., format = "list", fill = NULL)

Arguments

x

A survey design object or data.frame.

...

<tidy-select> Variables to query. Supports selection helpers: tidyselect::starts_with(), tidyselect::all_of(), tidyselect::any_of(), tidyselect::matches(), etc. If empty, returns the payload for every column in x. Use tidyselect::any_of() to silently skip missing variable names.

format

character(1). Output format: "list" (default) or "data_frame". "named_vector" is not valid for this function (payloads are not scalar).

fill

Scalar or NULL. How to handle variables with no payload: NULL (default) omits them; NA_character_ includes them as NULL entries in "list" format. In "data_frame" format, variables with no payload are always excluded regardless of fill.

Value

  • "list" (default): named list. Keys are variable names; values are each variable's stored payload, or NULL for variables included via fill = NA_character_ with no payload set. Empty: list().

  • "data_frame": a tibble with columns variable (character), key (character), and value (a list-column, one raw payload value per row, unvalidated and untouched). One row per (variable, key) pair; a variable whose payload is list() or unset contributes zero rows. Empty: a zero-row tibble typed as above.

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"
#> 
#> 
extract_var_extra(d, age, format = "data_frame")
#> # A tibble: 1 × 3
#>   variable key   value    
#>   <chr>    <chr> <list>   
#> 1 age      role  <chr [1]>