@@ -28,7 +28,7 @@ process_qsf <- function(path_to_qsf,
28
28
path_to_rename_map <- localize_static_filepath(rename_map_file , survey_version )
29
29
path_to_drop_columns <- localize_static_filepath(drop_columns_file , survey_version )
30
30
31
- q <- read_json(path_to_qsf )
31
+ q <- read_json(path_to_qsf , encoding = " UTF-8 " )
32
32
wave <- get_wave(path_to_qsf )
33
33
34
34
displayed_questions <- subset_qsf_to_displayed(q )
@@ -108,7 +108,7 @@ process_qsf <- function(path_to_qsf,
108
108
}
109
109
)
110
110
111
- # get the "answers". These are answer choices for matrix items, and missing for non-matrix items .
111
+ # get the "answers". These are answer choices for matrix and dropdown items, and missing for other questions .
112
112
matrix_answers <- displayed_questions %> %
113
113
map(~ .x $ Payload $ Answers ) %> %
114
114
map(~ map(.x , " Display" ))
@@ -123,7 +123,7 @@ process_qsf <- function(path_to_qsf,
123
123
}) %> % unlist() %> % which()
124
124
125
125
# Swap matrix answer choices into `choices` and matrix subquestion text into another variable
126
- ii_matrix <- which(qtype == " Matrix" )
126
+ ii_matrix <- which(qtype == " Matrix" | qtype == " Dropdown " )
127
127
matrix_subquestions <- rep(list (list ()), length(choices ))
128
128
matrix_subquestions [ii_matrix ] <- choices [ii_matrix ]
129
129
choices [ii_matrix ] <- matrix_answers [ii_matrix ]
@@ -142,14 +142,18 @@ process_qsf <- function(path_to_qsf,
142
142
map(~ .x $ Payload $ Answers ) %> %
143
143
map(~ map(.x , ~ map(.x , " Display" )))
144
144
145
+ # Null out dropdown choices to avoid including super long list.
146
+ ii_dropdown <- which(qtype == " Dropdown" )
147
+ choices [ii_dropdown ] <- rep(list (" Response options not listed due to length. Please see additional documentation" ), length(ii_dropdown ))
148
+
145
149
# Get matrix subquestion field names as reported in microdata. NULL if not
146
150
# defined (not a Matrix question); FALSE if not set; otherwise a list
147
151
matrix_subquestion_field_names <- displayed_questions %> %
148
152
map(~ .x $ Payload $ ChoiceDataExportTags )
149
153
# When subquestion field names are not set, generate incrementing names
150
154
ii_unset_matrix_subq_names <- (matrix_subquestion_field_names %> %
151
155
map(~ ! inherits(.x , " list" )) %> %
152
- unlist() & qtype == " Matrix" ) %> %
156
+ unlist() & ( qtype == " Matrix" | qtype == " Dropdown " )) %> %
153
157
which()
154
158
matrix_subquestion_field_names [ii_unset_matrix_subq_names ] <- lapply(ii_unset_matrix_subq_names , function (ind ){
155
159
paste(
@@ -331,18 +335,18 @@ process_qsf <- function(path_to_qsf,
331
335
332
336
# separate matrix subquestions into separate fields (to match exported data)
333
337
nonmatrix_items <- qdf %> %
334
- filter(question_type != " Matrix" ) %> %
338
+ filter(question_type != " Matrix" & question_type != " Dropdown " ) %> %
335
339
mutate(matrix_base_name = NA_character_ ) %> %
336
340
select(- matrix_subquestion_field_names )
337
341
338
342
has_response_by_subq <- qdf %> %
339
- filter(question_type == " Matrix" ) %> %
343
+ filter(question_type == " Matrix" | question_type == " Dropdown " ) %> %
340
344
pull(response_options ) %> %
341
345
map_lgl(~ all(map_lgl(.x , ~ inherits(.x , " list" ))) &&
342
346
! identical(.x , list ()))
343
347
344
348
matrix_items <- qdf %> %
345
- filter(question_type == " Matrix" ) %> %
349
+ filter(question_type == " Matrix" | question_type == " Dropdown " ) %> %
346
350
filter(! has_response_by_subq ) %> %
347
351
rowwise() %> %
348
352
mutate(new = list (
@@ -364,7 +368,7 @@ process_qsf <- function(path_to_qsf,
364
368
365
369
366
370
matrix_items_resp_by_subq <- qdf %> %
367
- filter(question_type == " Matrix" ) %> %
371
+ filter(question_type == " Matrix" | question_type == " Dropdown " ) %> %
368
372
filter(has_response_by_subq ) %> %
369
373
rowwise() %> %
370
374
mutate(new = list (
@@ -395,8 +399,6 @@ process_qsf <- function(path_to_qsf,
395
399
mutate(variable = if_else(str_starts(variable , " C10" ), paste0(variable , " _1" ), variable ),
396
400
question_type = if_else(str_starts(variable , " A5|C10" ), " Text" , question_type ),
397
401
response_options = if_else(str_starts(variable , " A5|C10" ), list (list ()), response_options ))
398
- } else if (survey_version == " UMD" ) {
399
- # pass
400
402
}
401
403
402
404
qdf <- bind_rows(nonmatrix_items , matrix_items )
0 commit comments