diff --git a/.gitignore b/.gitignore index 234f028..0d7f03b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .RData .Ruserdata docs +inst/doc diff --git a/DESCRIPTION b/DESCRIPTION index c51e67f..af5c0b5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,6 +30,8 @@ Imports: tibble Suggests: covr, + knitr, + rmarkdown, spelling, testthat (>= 3.0.0) Remotes: @@ -41,3 +43,4 @@ RoxygenNote: 7.3.1 Roxygen: list(markdown = TRUE) URL: https://github.com/OxfordIHTM/codeditr, http://oxford-ihtm.io/codeditr/ Config/testthat/edition: 3 +VignetteBuilder: knitr diff --git a/R/cod_summary.R b/R/cod_summary.R index 6059b90..19ca33a 100644 --- a/R/cod_summary.R +++ b/R/cod_summary.R @@ -12,7 +12,7 @@ #' @examples #' cod_check_code( #' cod_data_raw_example$code, version = "icd11", -#' sex = cod_data_raw_example$sex", age = cod_data_raw_example$age +#' sex = cod_data_raw_example$sex, age = cod_data_raw_example$age #' ) |> #' cod_check_code_summary() #' diff --git a/man/cod_check_code_summary.Rd b/man/cod_check_code_summary.Rd index 1177c80..2c7f5de 100644 --- a/man/cod_check_code_summary.Rd +++ b/man/cod_check_code_summary.Rd @@ -20,3 +20,11 @@ Otherwise, a tabulated summary of check outputs. \description{ Summarise cause-of-death check results } +\examples{ +cod_check_code( + cod_data_raw_example$code, version = "icd11", + sex = cod_data_raw_example$sex, age = cod_data_raw_example$age +) |> + cod_check_code_summary() + +} diff --git a/tests/testthat/test-cod_check_code.R b/tests/testthat/test-cod_check_code.R index 8f6e7a3..74e48d3 100644 --- a/tests/testthat/test-cod_check_code.R +++ b/tests/testthat/test-cod_check_code.R @@ -17,3 +17,33 @@ test_that("cod_check_code outputs appropriate results", { ) }) + +code <- c(sample(icd10_cod_neonate$code, size = 4), + sample(icd10_cod_child$code, size = 4)) +sex <- rep(c(1, 1, 2, 1), 2) +age <- c(0, 0, 1, 5, 0, 10, 11, 9) + +test_icd10_df <- data.frame(age, sex, code) + +code <- c(sample(icd11_cod_neonate$code, size = 4), + sample(icd11_cod_child$code, size = 4)) +sex <- rep(c(1, 1, 2, 1), 2) +age <- c(0, 0, 1, 5, 0, 10, 11, 9) + +test_icd11_df <- data.frame(age, sex, code) + +test_that("cod_check_code outputs appropriate age test results", { + expect_s3_class( + cod_check_code( + test_icd10_df$code, sex = test_icd10_df$sex, age = test_icd10_df$age + ), + "tbl" + ) + + expect_s3_class( + cod_check_code( + test_icd11_df$code, sex = test_icd11_df$sex, age = test_icd11_df$age + ), + "tbl" + ) +}) diff --git a/tests/testthat/test-cod_summary.R b/tests/testthat/test-cod_summary.R new file mode 100644 index 0000000..e81c76d --- /dev/null +++ b/tests/testthat/test-cod_summary.R @@ -0,0 +1,17 @@ +# Tests for cod_check_code_summary --------------------------------------------- + +test_summary_df <- cod_check_code( + cod_data_raw_example$code, version = "icd11", + sex = cod_data_raw_example$sex, age = cod_data_raw_example$age +) + + +testthat::test_that("cod_check_code_summary outputs appropriate results", { + expect_type(cod_check_code_summary(test_summary_df), "list") + + expect_s3_class( + cod_check_code_summary(test_summary_df, simplify = TRUE), "tbl" + ) +}) + + diff --git a/vignettes/.gitignore b/vignettes/.gitignore new file mode 100644 index 0000000..097b241 --- /dev/null +++ b/vignettes/.gitignore @@ -0,0 +1,2 @@ +*.html +*.R diff --git a/vignettes/codeditr.Rmd b/vignettes/codeditr.Rmd new file mode 100644 index 0000000..3de7489 --- /dev/null +++ b/vignettes/codeditr.Rmd @@ -0,0 +1,21 @@ +--- +title: "Implementing Cause-of-Death Data Checks with codeditr" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Implementing Cause-of-Death Data Checks with codeditr} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +```{r setup} +library(codeditr) +``` + +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. The aim is to leverage the utility and function of the original tool into a usable application program interface (API) 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.