diff --git a/R/cod_check_age.R b/R/cod_check_age.R index 8158603..f284d47 100644 --- a/R/cod_check_age.R +++ b/R/cod_check_age.R @@ -47,27 +47,22 @@ cod_check_age <- function(age_value, age_check <- vector(mode = "integer", length = length(age_value)) ## Classify errors/issues ---- - if (age_type == "D") { - age_check <- ifelse(age_value >= 28 & age_value <= 31, 1, age_check) - age_check <- ifelse(age_value > 31, 2, age_check) - } + age_check[age_type == "D" & age_value >= 28 & age_value <= 31] <- 1L + age_check[age_type == "D" & age_value > 31] <- 2L - if (age_type == "M") { - age_check <- ifelse(age_value < 1, 3, age_check) - age_check <- ifelse(age_value >= 12, 4, age_check) - } + age_check[age_type == "M" & age_value < 1] <- 3L + age_check[age_type == "M" & age_value >= 12] <- 4L - if (age_type == "Y") { - age_check <- ifelse(age_value < 1, 5, age_check) - age_check <- ifelse(age_value > 125, 6, age_check) - } + age_check[age_type == "Y" & age_value < 1] <- 5L + age_check[age_type == "Y" & age_value > 125] <- 6L - if (is.na(age_value)) age_check <- 7 - if (is.na(age_type)) age_check <- 8 + age_check[is.na(age_value) & !is.na(age_type)] <- 7L + age_check[!is.na(age_value) & is.na(age_type)] <- 8L + age_check[is.na(age_value) & is.na(age_type)] <- 9L age_check_note <- cut( x = age_check, - breaks = c(0, 1, 2, 3, 4, 5, 6, 7, 8, Inf), + breaks = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, Inf), labels = c( "No issues with age value and age type", "Should probably be age value of 1 and age type of months (M)", @@ -77,12 +72,13 @@ cod_check_age <- function(age_value, "Should probably be converted to age value of age type months (M)", "Age value is more than 125 years which is highly unlikely", "Missing age value", - "Missing age type" + "Missing age type", + "Missing age value and age type" ), include.lowest = TRUE, right = FALSE ) - ## Return age checks ---- tibble::tibble(age_check, age_check_note) } + diff --git a/R/cod_check_sex.R b/R/cod_check_sex.R new file mode 100644 index 0000000..f2de113 --- /dev/null +++ b/R/cod_check_sex.R @@ -0,0 +1,35 @@ +#' +#' Check sex values in cause of death data based on CoDEdit rules +#' +#' @param sex_value An integer value or vector of values for age based on the +#' CoDEdit rules. +#' + +cod_check_sex <- function(sex_value) { + ## Create sex_check vector ---- + sex_check <- vector(mode = "integer", length = length(sex_value)) + + ## Check that sex_value is of the correct class ---- + sex_check <- ifelse(!is.integer(sex_value), 1L, sex_check) + + ## Check that sex_value is either 1L for males, 2L for females, and 9L for + ## unknown + sex_check <- ifelse( + any(!sex_value %in% c(1L, 2L, 9L)), sex_check + 2L, sex_check + ) + + + ## Check if sex_value is missing ---- + sex_check <- ifelse(is.na(sex_value), sex_check + 4L, sex_check) + + ## Create sex_check note vector ---- + sex_check_note <- vector(mode = "character", length = length(sex_value)) + + sex_check_note[sex_check == 0] <- "No issues with sex values" + sex_check_note[sex_check == 1] <- "Sex value is not an integer" + sex_check_note[sex_check == 2] <- "Sex value is not any of the expected values" + sex_check_note[sex_check == 3] <- "Sex value is not an integer; Sex value is not any of the expected values" + sex_check_note[sex_check == 4] <- "Missing sex value" + sex_check_note[sex_check == 5] <- "" + +} diff --git a/_pkgdown.yml b/_pkgdown.yml deleted file mode 100644 index 73fee23..0000000 --- a/_pkgdown.yml +++ /dev/null @@ -1,4 +0,0 @@ -url: http://oxford-ihtm.io/codeditr/ -template: - bootstrap: 5 -