diff --git a/R/concept-area.R b/R/concept-area.R index 294a011..a10a9a6 100644 --- a/R/concept-area.R +++ b/R/concept-area.R @@ -6,5 +6,7 @@ as_area <- function(x) { stopifnot(all(x %in% c("1", "2", "urban", "rural", NA_character_))) x[x == "1"] <- "Urban" x[x == "2"] <- "Rural" + x[x == "urban"] <- "Urban" + x[x == "rural"] <- "Rural" factor(x, levels = area_levels, ordered = FALSE) } diff --git a/R/concepts.R b/R/concepts.R index ead3b80..e2697b5 100644 --- a/R/concepts.R +++ b/R/concepts.R @@ -85,7 +85,10 @@ concepts <- concepts_list( concept( key = "pregnancymonths", label = "Pregnancy Months", - acceptor = concept_acceptor(is.numeric, "TODO"), + acceptor = concept_acceptor( + is.numeric, + "Preganancy Months should be a numeric value." + ), standardizer = identity, validator = is.numeric, prototype = NA_real_ @@ -94,7 +97,10 @@ concepts <- concepts_list( concept( key = "pregnancyweeks", label = "Pregnancy Weeks", - acceptor = concept_acceptor(is.numeric, "TODO"), + acceptor = concept_acceptor( + is.numeric, + "Preganancy Weeks should be a numeric value." + ), standardizer = identity, validator = is.numeric, prototype = NA_real_ @@ -171,7 +177,10 @@ concepts <- concepts_list( concept( key = "smokes_cigarettes_per_day", label = "Number of cigarettes per day", - acceptor = concept_acceptor(is.numeric, "TODO"), + acceptor = concept_acceptor( + is.numeric, + "Number of cigarettes per day should be a numeric value." + ), standardizer = identity, validator = is.numeric, prototype = NA_real_ @@ -180,7 +189,10 @@ concepts <- concepts_list( concept( key = "altitude", label = "Elevation", - acceptor = concept_acceptor(is.numeric, "TODO"), + acceptor = concept_acceptor( + is.numeric, + "Elevation should be a numeric value." + ), standardizer = identity, validator = is.numeric, prototype = NA_real_ @@ -197,7 +209,7 @@ concepts <- concepts_list( ) && any(!is.na(x)) }, - "TODO" + "Area can only be '1', '2', 'urban' or 'rural'. All lower-case. At least one value must not be NA." ), standardizer = as_area, validator = \(x) is.factor(x) & all(levels(x) == area_levels), @@ -207,7 +219,10 @@ concepts <- concepts_list( concept( key = "region", label = "Region", - acceptor = concept_acceptor(\(x) is.character(x) | is.numeric(x), "TODO"), + acceptor = concept_acceptor( + \(x) is.character(x) | is.numeric(x), + "Region should be a numeric or a character value." + ), standardizer = as.character, validator = is.character, prototype = NA_character_ @@ -216,7 +231,10 @@ concepts <- concepts_list( concept( key = "wealth_quintile", label = "Wealth Quintile", - acceptor = concept_acceptor(wealth_quintiles_acceptor, "TODO"), + acceptor = concept_acceptor( + wealth_quintiles_acceptor, + "Wealth Quintiles must only be 1,2,3,4,5 or Q1,Q2,Q3,Q4,Q5 or NA." + ), standardizer = as_wealth_quintiles, validator = \(x) is.factor(x) & all(levels(x) == wealth_quintiles_levels), prototype = NA_character_ @@ -234,7 +252,7 @@ concepts <- concepts_list( ) && any(!is.na(x)) }, - "TODO" + "Mother's Education must be a numeric value of 0,1,2,3 or NA." ), standardizer = as_mothers_education, validator = \(x) is.factor(x) & all(levels(x) == mothers_education_levels), @@ -244,7 +262,10 @@ concepts <- concepts_list( concept( key = "sample_weight", label = "Sample Weight", - acceptor = concept_acceptor(is.numeric, "TODO"), + acceptor = concept_acceptor( + is.numeric, + "Sample Weight must be a numeric value." + ), standardizer = identity, validator = is.numeric, prototype = NA_real_ @@ -253,7 +274,10 @@ concepts <- concepts_list( concept( key = "iodine", label = "Urinary Iodine Concentration (\u00b5g/L)", - acceptor = concept_acceptor(is.numeric, "TODO"), + acceptor = concept_acceptor( + is.numeric, + "Urinary Iodine Concentration must be a numeric value." + ), standardizer = identity, validator = is.numeric, prototype = measurement_g_l(NA_real_), @@ -263,7 +287,10 @@ concepts <- concepts_list( concept( key = "haemoglobin", label = "Haemoglobin (g/L)", - acceptor = concept_acceptor(is.numeric, "TODO"), + acceptor = concept_acceptor( + is.numeric, + "Haemoglobin must be a numeric value." + ), standardizer = identity, validator = is.numeric, prototype = measurement_g_l(NA_real_), @@ -273,7 +300,10 @@ concepts <- concepts_list( concept( key = "ferritin", label = "Ferritin (\u00b5g/L)", - acceptor = concept_acceptor(is.numeric, "TODO"), + acceptor = concept_acceptor( + is.numeric, + "Ferritin must be a numeric value." + ), standardizer = identity, validator = is.numeric, prototype = measurement_mcg_l(NA_real_), @@ -283,7 +313,7 @@ concepts <- concepts_list( concept( key = "AGP", label = "AGP", - acceptor = concept_acceptor(is.numeric, "TODO"), + acceptor = concept_acceptor(is.numeric, "AGP must be a numeric value."), standardizer = identity, validator = is.numeric, prototype = measurement_g_l(NA_real_), @@ -293,7 +323,7 @@ concepts <- concepts_list( concept( key = "CRP", label = "CRP", - acceptor = concept_acceptor(is.numeric, "TODO"), + acceptor = concept_acceptor(is.numeric, "CRP must be a numeric value."), standardizer = identity, validator = is.numeric, prototype = measurement_mg_l(NA_real_), @@ -302,8 +332,11 @@ concepts <- concepts_list( ## other_grouping_variable ---- concept( key = "other_grouping_variable", - label = "Other filter", - acceptor = concept_acceptor(\(x) is.character(x) | is.numeric(x), "TODO"), + label = "Other grouping", + acceptor = concept_acceptor( + \(x) is.character(x) | is.numeric(x), + "Other group must be either a character or numeric value." + ), standardizer = as.character, validator = is.character, prototype = NA_character_ @@ -312,7 +345,7 @@ concepts <- concepts_list( concept( key = "cluster", label = "Cluster", - acceptor = concept_acceptor(is.numeric, "TODO"), + acceptor = concept_acceptor(is.numeric, "Cluster must be a numeric value."), standardizer = identity, validator = is.numeric, prototype = NA_integer_ @@ -321,7 +354,7 @@ concepts <- concepts_list( concept( key = "strata", label = "Strata", - acceptor = concept_acceptor(is.numeric, "TODO"), + acceptor = concept_acceptor(is.numeric, "Strata must be a numeric value."), standardizer = identity, validator = is.numeric, prototype = NA_integer_ @@ -338,7 +371,7 @@ concepts <- concepts_list( ) && any(!is.na(x)) }, - "TODO" + "Fasting must be '1', 'yes', 'y' for 'yes' or '2', 'no','n' for 'no'." ), standardizer = as.character, validator = is.character, @@ -356,7 +389,7 @@ concepts <- concepts_list( ) && any(!is.na(x)) }, - "TODO" + "Malaria must be '1', 'yes', 'y' for 'yes' or '2', 'no','n' for 'no'." ), standardizer = function(x) { x <- as.character(x) diff --git a/R/indicators-export.R b/R/indicators-export.R index d62d4ae..8b1ae28 100644 --- a/R/indicators-export.R +++ b/R/indicators-export.R @@ -5,7 +5,7 @@ #' #' Notes: #' \itemize{ -#' \item \code{indicator_iodine} does not produce individual level classifications. +#' \item \code{indicator_iodine} does not produce individual level classifications. All results are 'NA'. #' } #' @include indicators-anaemia.R #' @rdname indicators diff --git a/R/indicators.R b/R/indicators.R index 0bc44b9..a9e8f3f 100644 --- a/R/indicators.R +++ b/R/indicators.R @@ -396,7 +396,11 @@ indicators_compute_all <- function(indicators, values, concepts) { } else { tibble::tibble( result = result, - input_value = indicator_adjust_value(indicator, base_values[[i]], concepts) + input_value = indicator_adjust_value( + indicator, + base_values[[i]], + concepts + ) ) } } diff --git a/README.md b/README.md index 9dfcc55..47a0936 100644 --- a/README.md +++ b/README.md @@ -102,8 +102,7 @@ result <- mn_stats( ``` r covr::package_coverage() -#> micronutrients Coverage: 77.72% -#> R/concept-area.R: 0.00% +#> micronutrients Coverage: 78.10% #> R/concept-fasting-status.R: 0.00% #> R/concept-helpers.R: 0.00% #> R/concept-iron-deficiency.R: 0.00% @@ -121,10 +120,11 @@ covr::package_coverage() #> R/concepts.R: 85.37% #> R/age.R: 85.71% #> R/concept-pregnancy-status.R: 87.50% -#> R/indicators.R: 88.89% +#> R/indicators.R: 89.13% #> R/age-groups.R: 89.61% #> R/prevalence.R: 96.80% #> R/adjustments-export.R: 100.00% #> R/classifications.R: 100.00% +#> R/concept-area.R: 100.00% #> R/indicators-export.R: 100.00% ``` diff --git a/man/indicators.Rd b/man/indicators.Rd index 11f88d8..cca651c 100644 --- a/man/indicators.Rd +++ b/man/indicators.Rd @@ -21,6 +21,6 @@ indicator_iodine() \description{ Notes: \itemize{ -\item \code{indicator_iodine} does not produce individual level classifications. +\item \code{indicator_iodine} does not produce individual level classifications. All results are 'NA'. } } diff --git a/tests/testthat/test-concepts.R b/tests/testthat/test-concepts.R index 54fab30..c064f40 100644 --- a/tests/testthat/test-concepts.R +++ b/tests/testthat/test-concepts.R @@ -26,3 +26,14 @@ test_that("concepts_from_args: some concepts have default values if not supplied ) } }) + +test_that("area is properly encoded", { + x <- as_area(c("1", "2", "urban", "rural", NA_character_)) + expect_equal( + x, + factor( + c("Urban", "Rural", "Urban", "Rural", NA_character_), + levels = area_levels + ) + ) +}) diff --git a/tests/testthat/test-prevalence.R b/tests/testthat/test-prevalence.R index 63bea66..7098753 100644 --- a/tests/testthat/test-prevalence.R +++ b/tests/testthat/test-prevalence.R @@ -22,7 +22,8 @@ test_that("mn_stats", { pregnancyweeks = testdata$pregnancyweeks, pregnancymonths = testdata$pregnancymonths, cluster = 1:nrow(testdata), - strata = rep.int(1, nrow(testdata)) + strata = rep.int(1, nrow(testdata)), + area = testdata$area ) expect_true(is.data.frame(res)) expect_true(nrow(res) > 0) @@ -112,4 +113,7 @@ test_that("mn_stats", { "ida_adj_ul" ) ) + expect_true( + all(c("Area: Urban", "Area: Rural") %in% res$Group) + ) })