Skip to content

Commit

Permalink
Make condition logic more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
ldavies99 committed Nov 14, 2023
1 parent 2596c50 commit eaf4744
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions R/question-routing.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,27 @@

apply_skip_logic <- function(data) {

conditions <- list(data$workplace != "NHS or local healthcare service",
data$workplace %in%
conditions <- list(data$workplace == "NHS or local healthcare service",
!(data$workplace %in%
c("Civil service, including devolved administrations",
"NHS or local healthcare service",
"test"),
data$department != "Office for National Statistics",
data$department %in% c("Office for National Statistics", "test"),
!is.na(data$ONS_directorate),
data$pay_band != "Local Authority or NJC",
data$pay_band != "Other / Not sure",
!is.na(data$NHS_band),
data$primary_work_country != "Scotland",
data$primary_work_country != "Wales",
data$primary_work_country != "Northern Ireland",
!is.na(data$England_NHS_organisation),
!is.na(data$Scotland_NHS_organisation),
!is.na(data$Wales_NHS_organisation),
data$highest_qualification != "Any other qualification",
data$code_freq != "Never",
data$other_coding_experience != "No",
data$heard_of_RAP != "No",
data$have_RAP_champ %in% c("Yes", "test"))
"NHS or local healthcare service")),
data$department == "Office for National Statistics",
!(data$department %in% c("Office for National Statistics")),
is.na(data$ONS_directorate),
data$pay_band == "Local Authority or NJC",
data$pay_band == "Other / Not sure",
is.na(data$NHS_band),
data$primary_work_country == "Scotland",
data$primary_work_country == "Wales",
data$primary_work_country == "Northern Ireland",
is.na(data$England_NHS_organisation),
is.na(data$Scotland_NHS_organisation),
is.na(data$Wales_NHS_organisation),
data$highest_qualification == "Any other qualification",
data$code_freq == "Never",
data$other_coding_experience == "No",
data$heard_of_RAP == "No",
!(data$have_RAP_champ %in% c("Yes")))

skipped_cols <- list(colnames(data)[which(colnames(data) == "CS_grade"):which(colnames(data) == "ONS_directorate")],
colnames(data)[which(colnames(data) == "CS_grade"):which(colnames(data) == "Northern_Ireland_NHS_organisation")],
Expand Down Expand Up @@ -78,10 +77,9 @@ apply_skip_logic <- function(data) {

check_skip_logic <- function(data, condition, skipped_cols) {

condition_failed <- !condition & !is.na(data[skipped_cols])

row_failed <- as.logical(rowSums(condition_failed))
condition_met <- condition & !is.na(data[skipped_cols])

row_failed <- as.logical(rowSums(condition_met))

return(
which(row_failed)
Expand Down

0 comments on commit eaf4744

Please sign in to comment.