Skip to content

Commit 8cfd2d8

Browse files
committed
remove occasional brackets around response options
1 parent c3c2fae commit 8cfd2d8

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

facebook/qsf-tools/generate-codebook.R

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,11 @@ process_qsf <- function(path_to_qsf,
452452
qdf <- rbind(qdf, other_text_items)
453453
qdf$response_options[qdf$question_type == "Text"] <- NA
454454

455-
455+
# Drop occasional start and end square brackets from matrix response options.
456+
qdf <- qdf %>%
457+
mutate(
458+
response_options = map_chr(response_options, ~ remove_brackets(.x))
459+
)
456460

457461
# Quality checks
458462
stopifnot(length(qdf$variable) == length(unique(qdf$variable)))
@@ -467,6 +471,14 @@ process_qsf <- function(path_to_qsf,
467471
return(qdf %>% rename(version = wave))
468472
}
469473

474+
remove_brackets <- function(response_set) {
475+
if ( !is.na(response_set) && startsWith(response_set, "[") && endsWith(response_set, "]") ) {
476+
str_sub(response_set, 2, -2)
477+
} else {
478+
response_set
479+
}
480+
}
481+
470482
#' Append the parsed and formatted info from the QSF to the existing codebook
471483
#'
472484
#' @param qdf dataframe containing parsed QSF data
@@ -511,7 +523,7 @@ add_qdf_to_codebook <- function(qdf,
511523
qdf <- qdf %>% select(-replaces)
512524
}
513525
}
514-
526+
515527
# Using rbind here to raise an error if columns differ between the existing
516528
# codebook and the new wave data.
517529
# Sort so that items with missing question_type (non-Qualtrics fields) are at the top.

0 commit comments

Comments
 (0)