Extracts a single questionnaire item field value for every first- for every second-level iterator from the raw FOKUS questionnaire data based on the specified variable name and branch path.
Usage
qstnr_item_val(
ballot_date = pal::pkg_config_val("ballot_date"),
canton = cantons(ballot_date),
branch_path,
var_name,
key = qstnr_item_keys$key,
lvl = "?",
i = NA_integer_,
j = NA_integer_
)
Arguments
- ballot_date
FOKUS-covered ballot date. One of
"2018-09-23"
"2018-11-25"
"2019-10-20"
"2020-09-27"
"2020-10-18"
"2021-11-28"
"2023-06-18"
"2024-10-20"
- canton
FOKUS-covered canton name. One of
"aargau"
- branch_path
Sequence of questionnaire table levels that lead to the
item
leaf node wherevar_name
is defined. A character vector.- var_name
Variable name, without resolved string interpolation, i.e. 1:1 as stated in the raw FOKUS questionnaire data. A character scalar.
- key
Questionnaire item key. One of
"lvl"
"i"
"j"
"block"
"variable_name"
"who"
"topic"
"question_intro_i"
"question_intro_j"
"question"
"question_full"
"question_common"
"variable_label"
"variable_label_common"
"response_options"
"variable_values"
"value_labels"
"value_scale"
"allow_multiple_answers"
"randomize_response_options"
"is_mandatory"
"ballot_types"
"include"
- lvl
Political-level loop iterator that can be referred to in field value via string interpolation. A character vector.
- i
Second-level loop iterator that can be referred to in field value via string interpolation. An integerish vector.
- j
Third-level loop iterator that can be referred to in field value via string interpolation. An integerish vector.
Details
When used in questionnaire item field values via string interpolation, be careful to not create infinite loops via circular references.
See also
Other questionnaire-internal functions:
qstnr_parties()
,
qstnr_response_option_codes()
Examples
fokus:::qstnr_item_val(ballot_date = "2018-09-23",
canton = "aargau",
branch_path = c("03_proposal_specific", "004_participants"),
var_name = "appeal_federal_proposals",
key = "include")
#> [1] TRUE
fokus:::qstnr_item_val(
ballot_date = "2019-10-20",
canton = "aargau",
branch_path = c("02_political_start", "002_non_participation",
"003_election", "z01_hypothetical"),
var_name = "hypothetical_voting_decision_federal_majoritarian_election_{i}_seat_{j}",
key = "topic",
i = 1:2,
j = 1:3
)
#> [1] "Hypothetischer Stimmentscheid Sitz 1 eidgenössische Mehrheitswahl 1" "Hypothetischer Stimmentscheid Sitz 2 eidgenössische Mehrheitswahl 1"
#> [3] "Hypothetischer Stimmentscheid Sitz 3 eidgenössische Mehrheitswahl 1" "Hypothetischer Stimmentscheid Sitz 1 eidgenössische Mehrheitswahl 2"
#> [5] "Hypothetischer Stimmentscheid Sitz 2 eidgenössische Mehrheitswahl 2" "Hypothetischer Stimmentscheid Sitz 3 eidgenössische Mehrheitswahl 2"