Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ Imports:
tibble
Suggests:
covr,
spelling
spelling,
testthat (>= 3.0.0)
Encoding: UTF-8
Language: en-GB
LazyData: true
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
Config/testthat/edition: 3
2 changes: 1 addition & 1 deletion R/cod_recode_sex.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#' @export
#'

cod_recode_sex <- function(sex_value, sex_code = c(1, 2), codedit = TRUE) {
cod_recode_sex <- function(sex_value, sex_code = c(1L, 2L), codedit = TRUE) {
if (codedit) {
sex_value[!sex_value %in% sex_code] <- 9L
} else {
Expand Down
1 change: 1 addition & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ knitr::opts_chunk$set(
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/OxfordIHTM/codeditr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/OxfordIHTM/codeditr/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/OxfordIHTM/codeditr/branch/main/graph/badge.svg)](https://app.codecov.io/gh/OxfordIHTM/codeditr?branch=main)
[![CodeFactor](https://www.codefactor.io/repository/github/OxfordIHTM/codeditr/badge)](https://www.codefactor.io/repository/github/OxfordIHTM/codeditr)
<!-- badges: end -->

The [World Health Organization](https://www.who.int/)'s [CoDEdit electronic tool](https://www.who.int/standards/classifications/classification-of-diseases/services/codedit-tool) is intended to help producers of cause-of-death statistics in strengthening their capacity to perform routine checks on their data. This package ports the original tool built using Microsoft Access into R so as to leverage the utility and function of the original tool into a usable application program interface that can be used for building more universal tools or for creating programmatic scientific workflows aimed at routine, automated, and large-scale monitoring of cause-of-death data.
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](h
[![R-CMD-check](https://github.com/OxfordIHTM/codeditr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/OxfordIHTM/codeditr/actions/workflows/R-CMD-check.yaml)
[![Codecov test
coverage](https://codecov.io/gh/OxfordIHTM/codeditr/branch/main/graph/badge.svg)](https://app.codecov.io/gh/OxfordIHTM/codeditr?branch=main)
[![CodeFactor](https://www.codefactor.io/repository/github/OxfordIHTM/codeditr/badge)](https://www.codefactor.io/repository/github/OxfordIHTM/codeditr)
<!-- badges: end -->

The [World Health Organization](https://www.who.int/)’s [CoDEdit
Expand Down Expand Up @@ -69,17 +70,17 @@ follows:

``` r
citation("codeditr")
#> To cite zscorer in publications use:
#> To cite codeditr in publications use:
#>
#> Anita Makori and Ernest Guevarra (2024). codeditr: Implementing Basic
#> Checks on Cause-of-Death Data Based on World Health Organization's
#> CoDEdit Tool. R package version 0.0.9000. URL
#> https://oxford-ihtm.io/codeditr/
#> Anita Makori, Ernest Guevarra (2024). _codeditr: Implementing
#> Cause-of-Death Data Checks Based on World Health Organization's
#> CoDEdit Tool_. R package version 0.0.9000,
#> <https://oxford-ihtm.io/codeditr/>.
#>
#> A BibTeX entry for LaTeX users is
#>
#> @Manual{,
#> title = {codeditr: Implementing Basic Checks on Cause-of-Death Data Based on World Health Organization's CoDEdit Tool},
#> title = {codeditr: Implementing Cause-of-Death Data Checks Based on World Health Organization's CoDEdit Tool},
#> author = {{Anita Makori} and {Ernest Guevarra}},
#> year = {2024},
#> note = {R package version 0.0.9000},
Expand Down
2 changes: 1 addition & 1 deletion man/cod_recode_sex.Rd

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

12 changes: 12 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(codeditr)

test_check("codeditr")
97 changes: 97 additions & 0 deletions tests/testthat/test-cod_recode_age_type.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Tests for recode age type ----------------------------------------------------

age_type <- c(rep("D", 3), rep("M", 2), rep("Y", 3))

age_type1 <- c(rep("d", 3), rep("m", 2), rep("y", 3))
age_type_code1 <- c("d", "m", "y")

age_type2 <- c(rep("days", 3), rep("months", 2), rep("years", 3))
age_type_code2 <- c("days", "months", "years")

age_type3 <- c(rep(1L, 3), rep(2L, 2), rep(3L, 3))
age_type_code3 <- c(1L, 2L, 3L)

age_type4 <- c(rep("d", 3), "m", NA_character_, rep("y", 3))
age_type_code4 <- c("d", "m", "y")

age_type5 <- c(rep(1L, 3), 2L, NA_integer_, rep(3L, 3))
age_type_code5 <- c(1L, 2L, 3L)

expected <- c(rep("D", 3), rep("M", 2), rep("Y", 3))
expected_na <- c(rep("D", 3), "M", NA_character_, rep("Y", 3))


testthat::test_that(
"output of recode age type is as expected", {
expect_vector(
cod_recode_age_type(age_type = age_type),
ptype = character(),
size = 8
)

expect_equal(
cod_recode_age_type(age_type = age_type),
expected
)

## input is different characters ----
expect_vector(
cod_recode_age_type(age_type = age_type1, age_type_code = age_type_code1),
ptype = character(),
size = 8
)

expect_equal(
cod_recode_age_type(age_type = age_type1, age_type_code = age_type_code1),
expected
)

## input is different characters ----
expect_vector(
cod_recode_age_type(age_type = age_type2, age_type_code = age_type_code2),
ptype = character(),
size = 8
)

expect_equal(
cod_recode_age_type(age_type = age_type2, age_type_code = age_type_code2),
expected
)

## input is integer ----
expect_vector(
cod_recode_age_type(age_type = age_type3, age_type_code = age_type_code3),
ptype = character(),
size = 8
)

expect_equal(
cod_recode_age_type(age_type = age_type3, age_type_code = age_type_code3),
expected
)

## input has NA ----
expect_vector(
cod_recode_age_type(age_type = age_type4, age_type_code = age_type_code4),
ptype = character(),
size = 8
)

expect_equal(
cod_recode_age_type(age_type = age_type4, age_type_code = age_type_code4),
expected_na
)

## input has NA ----
expect_vector(
cod_recode_age_type(age_type = age_type5, age_type_code = age_type_code5),
ptype = character(),
size = 8
)

expect_equal(
cod_recode_age_type(age_type = age_type5, age_type_code = age_type_code5),
expected_na
)
}
)
47 changes: 47 additions & 0 deletions tests/testthat/test-cod_recode_sex.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Tests for recode sex ---------------------------------------------------------

sex_value <- c(rep(1L, 2), rep(2L, 3), NA_integer_)

sex_value1 <- c(rep("m", 2), rep("f", 3), NA_character_)
sex_code1 <- c("m", "f")

expected <- c(1L, 1L, 2L, 2L, 2L, NA_integer_)
expected_codedit <- c(1L, 1L, 2L, 2L, 2L, 9L)

testthat::test_that(
"output of recode sex is as expected", {
expect_vector(
cod_recode_sex(sex_value = sex_value), ptype = integer(), size = 6
)

expect_equal(cod_recode_sex(sex_value = sex_value), expected_codedit)

expect_vector(
cod_recode_sex(
sex_value = sex_value1, sex_code = sex_code1, codedit = FALSE
),
ptype = integer(),
size = 6
)

expect_equal(
cod_recode_sex(
sex_value = sex_value1, sex_code = sex_code1, codedit = FALSE
),
expected
)

expect_vector(
cod_recode_sex(sex_value = sex_value1, sex_code = sex_code1),
ptype = integer(),
size = 6
)

expect_equal(
cod_recode_sex(
sex_value = sex_value1, sex_code = sex_code1, codedit = TRUE
),
expected_codedit
)
}
)