Skip to content

Commit

Permalink
create recode age type function
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestguevarra committed Apr 26, 2024
1 parent a744fe6 commit 600707d
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 7 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export(cod_calculate_age)
export(cod_check_age)
export(cod_recode_age_type)
export(cod_recode_sex)
export(get_age_values)
importFrom(dplyr,case_when)
Expand Down
7 changes: 3 additions & 4 deletions R/cod_check_age.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ cod_check_age <- function(age_value,
)

## Recode age_type ----
age_type[age_type == age_type_code[1]] <- "D"
age_type[age_type == age_type_code[2]] <- "M"
age_type[age_type == age_type_code[3]] <- "Y"
age_type[!age_type %in% age_type_code] <- NA_character_
age_type <- cod_recode_age_type(
age_type = age_type, age_type_code = age_type_code
)

## Create age_score vector ----
age_check <- vector(mode = "integer", length = length(age_value))
Expand Down
9 changes: 9 additions & 0 deletions R/cod_check_missing.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#'
#' Check missing information needed by CoDEdit tool
#'
#'
#'

cod_check_missing <- function() {

}
38 changes: 38 additions & 0 deletions R/cod_recode_age_type.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#'
#' Recode age type of cause of death data based on CoDEdit rules
#'
#' @param age_type A vector of values for age type based on the CoDEdit rules.
#' This should either be "D" for age in days, "M" for age
#' in months, or "Y" for age in years. If values are different from these,
#' then `age_type_code` should be specified to correspond to the day, month,
#' and year values of `age_type`.
#' @param age_type_code A character or integer vector of 3 values that indicate
#' which values are to be considered pertaining to days (first value in the
#' vector), to months (second value in the vector), or years (third value
#' in the vector).
#'
#' @returns A character value or vector of values containing either "D", "M",
#' or "Y" for *days*, *months*, or *years* respectively.
#'
#' @examples
#' cod_recode_age_type(
#' age_type = c(rep("d", 3), rep("m", 2), rep("y", 3)),
#' age_type_code = c("d", "m", "y")
#' )
#'
#' @rdname cod_recode_age_type
#' @export
#'

cod_recode_age_type <- function(age_type,
age_type_code = c("D", "M", "Y")) {
## Recode age_type ----
age_type[age_type == age_type_code[1]] <- "D"
age_type[age_type == age_type_code[2]] <- "M"
age_type[age_type == age_type_code[3]] <- "Y"
age_type[!age_type %in% c("D", "M", "Y")] <- NA_character_

## Return age_type ----
age_type
}

2 changes: 1 addition & 1 deletion R/cod_recode_sex.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#'
#' Recode cause of death data on sex
#' Recode sex value of cause of death data based on CoDEdit rules
#'
#' @param sex_value A character or integer value or vector of values signifying
#' the sex.
Expand Down
11 changes: 11 additions & 0 deletions man/cod_check_missing.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions man/cod_recode_age_type.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/cod_recode_sex.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 600707d

Please sign in to comment.