Groups variables by their shared question_preface metadata and classifies
each group as one of "single", "sata", or "battery". This is the single
source of truth used by downstream export functions to decide how to render
each question.
Arguments
- x
A survey design object or
data.frame.- ...
<
tidy-select> Variables to classify. Supports selection helpers:tidyselect::starts_with(),tidyselect::all_of(),tidyselect::any_of(), etc. Cannot be combined withvariable.- variable
character. Alternative programmatic interface: character vector of variable names. Cannot be combined with....
Value
A tibble with columns:
variable(character) — variable namequestion_preface(character) — the preface, orNAif nonetype(character) — one of"single","sata", or"battery"group(integer) — group id; variables with the same non-NA preface share a group
Details
The classification rules, applied per requested variable:
If the variable has no
question_preface, or is the only requested variable sharing its preface,type = "single".If a
question_prefaceis shared by 2+ requested variables and at least one is flagged viaset_sata(), all variables in that group gettype = "sata".Otherwise (shared preface, no SATA flag), all variables in the group get
type = "battery".
Group numbers are assigned sequentially by first appearance in the input.
See also
set_sata(), extract_sata(), set_question_preface()
Other metadata:
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_metadata(),
survey_weighting_history()
Examples
d <- as_survey(nhanes_2017, ids = sdmvpsu, weights = wtint2yr,
strata = sdmvstra, nest = TRUE)
d <- set_question_preface(d, riagendr = "Demographics",
ridageyr = "Demographics")
d <- set_sata(d, riagendr, ridageyr)
classify_question_type(d, riagendr, ridageyr, bpxsy1)
#> # A tibble: 3 × 4
#> variable question_preface type group
#> <chr> <chr> <chr> <int>
#> 1 riagendr Demographics sata 1
#> 2 ridageyr Demographics sata 1
#> 3 bpxsy1 NA single 2
