Skip to content

Fix pipeline when barrier column is all NAs #1346

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 1 commit into from
Oct 29, 2021
Merged
Changes from all 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
27 changes: 20 additions & 7 deletions facebook/delphiFacebook/R/variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,15 @@ code_vaccines <- function(input_data, wave) {
if ( all(c("V15a", "V15b") %in% names(input_data)) ) {
# introduced in Wave 11
vaccine_barriers <- coalesce(input_data$V15a, input_data$V15b)
vaccine_barriers <- ifelse(vaccine_barriers == "13", NA, vaccine_barriers)
vaccine_barriers <- split_options(vaccine_barriers)


# 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
if (any(!is.na(vaccine_barriers))) {
vaccine_barriers <- ifelse(vaccine_barriers == "13", NA_character_, 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")
input_data$v_vaccine_barrier_appointment_time <- is_selected(vaccine_barriers, "3")
Expand Down Expand Up @@ -685,12 +691,19 @@ code_vaccines <- function(input_data, wave) {
input_data$v_vaccine_barrier_type_has <- NA
input_data$v_vaccine_barrier_none_has <- NA
}

if ( "V15b" %in% names(input_data) ) {
# introduced in Wave 11
vaccine_barriers <- ifelse(input_data$V15b == "13", NA, input_data$V15b)
vaccine_barriers <- split_options(vaccine_barriers)

# 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
if (any(!is.na(input_data$V15b))) {
vaccine_barriers <- ifelse(input_data$V15b == "13", NA, input_data$V15b)
vaccine_barriers <- split_options(vaccine_barriers)
} else {
vaccine_barriers <- input_data$V15b
}

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")
input_data$v_vaccine_barrier_appointment_time_tried <- is_selected(vaccine_barriers, "3")
Expand Down