Skip to content

[CTIS] Make split_options return list of character missing if all input values are NA #1446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 10, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions facebook/delphiFacebook/R/variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
#' @return list of same length, each entry of which is a vector of selected
#' options
split_options <- function(column) {
return(strsplit(column, ",", fixed = TRUE))
if ( any(!is.na(column)) ) {
return(strsplit(column, ",", fixed = TRUE))
} else {
return(rep(NA_character_, length(column)))
}
}

#' Test if a specific selection is selected
Expand Down Expand Up @@ -649,15 +653,10 @@ code_vaccines <- function(input_data, wave) {
# introduced in Wave 11
vaccine_barriers <- coalesce(input_data$V15a, input_data$V15b)

# If the entire column is NA, ifelse() results in a logical vector, not a
# character vector, which confuses split_options; since the result should be
# NA anyway
vaccine_barriers <- as.character(
ifelse(vaccine_barriers == "13", NA_character_, vaccine_barriers)
)
if (any(!is.na(vaccine_barriers))) {
vaccine_barriers <- split_options(vaccine_barriers)
}
vaccine_barriers <- split_options(vaccine_barriers)

input_data$v_vaccine_barrier_eligible <- is_selected(vaccine_barriers, "1")
input_data$v_vaccine_barrier_no_appointments <- is_selected(vaccine_barriers, "2")
Expand Down Expand Up @@ -769,15 +768,10 @@ code_vaccines <- function(input_data, wave) {

if ( "V15b" %in% names(input_data) ) {
# introduced in Wave 11
# If the entire column is NA, ifelse() results in a logical vector, not a
# character vector, which confuses split_options; since the result should be
# NA anyway
vaccine_barriers <- as.character(
ifelse(input_data$V15b == "13", NA, input_data$V15b)
)
if (any(!is.na(vaccine_barriers))) {
vaccine_barriers <- split_options(vaccine_barriers)
}
vaccine_barriers <- split_options(vaccine_barriers)

input_data$v_vaccine_barrier_eligible_tried <- is_selected(vaccine_barriers, "1")
input_data$v_vaccine_barrier_no_appointments_tried <- is_selected(vaccine_barriers, "2")
Expand Down