diff --git a/R/_disable_autoload.r b/R/_disable_autoload.r new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index 0e75f1b..347f438 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# mwanaApp: A seamless graphical interface to the mwana R package for data wrangling, plausibility checks, and prevalence estimation +# mwanaApp: A graphical interface to the `mwana` R package for data wrangling, plausibility checks, and prevalence estimation of wasting @@ -33,7 +33,7 @@ The App can be installed from GitHub: ``` r # First install remotes package with: install.package("remotes") -# The install mwana package from GitHub with: +# The install mwana package from GitHub with: remotes::install_github(repo = "mphimo/mwanaApp", dependencies = TRUE) ``` diff --git a/README.qmd b/README.qmd index cae4050..c083c8b 100644 --- a/README.qmd +++ b/README.qmd @@ -2,7 +2,7 @@ format: gfm --- -# mwanaApp: A seamless graphical interface to the mwana R package for data wrangling, plausibility checks, and prevalence estimation +# mwanaApp: A graphical interface to the `mwana` R package for data wrangling, plausibility checks, and prevalence estimation of wasting [![R-CMD-check](https://github.com/mphimo/mwanaApp/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/mphimo/mwanaApp/actions/workflows/R-CMD-check.yaml) @@ -32,7 +32,7 @@ The App can be installed from GitHub: #| eval: false # First install remotes package with: install.package("remotes") -# The install mwana package from GitHub with: +# The install mwana package from GitHub with: remotes::install_github(repo = "mphimo/mwanaApp", dependencies = TRUE) ``` diff --git a/tests/testthat/fixtures/anthro-03.csv b/tests/testthat/fixtures/anthro-03.csv new file mode 100644 index 0000000..2b2ce17 --- /dev/null +++ b/tests/testthat/fixtures/anthro-03.csv @@ -0,0 +1,45 @@ +survey_area,survdate,cluster,team,id,hh,sex,birthdat,age,months,weight,height,oedema +District A,03/04/2026,2,2,,2,m,04/07/2023,,32.99,16.4,94.3,n +District A,03/04/2026,2,2,,2,f,01/05/2025,,11.07,9.7,76.2,n +District A,03/04/2026,2,2,,6,m,03/08/2023,,32,13.3,95.6,n +District A,03/04/2026,2,2,,5,m,22/08/2025,,7.36,8.2,65,n +District A,03/04/2026,2,2,,10,f,02/04/2023,,36.04,13.1,97.4,n +District A,03/04/2026,2,2,,10,f,20/05/2024,,22.44,9.4,81.5,n +District A,03/04/2026,2,2,,14,f,10/04/2025,,11.76,8.4,75.7,n +District A,03/04/2026,3,3,,5,m,23/11/2023,,28.32,11.1,85,n +District A,03/04/2026,3,3,,5,m,17/03/2025,,12.55,7.7,69.7,n +District A,03/04/2026,4,4,,2,f,02/08/2022,,44.02,11.7,97.1,n +District A,03/04/2026,4,4,,2,f,10/06/2024,,21.75,9.2,80,n +District A,03/04/2026,4,4,,4,m,20/09/2025,,6.41,5.6,64.4,n +District A,03/04/2026,4,4,,8,f,09/06/2024,,21.78,9.1,76.6,n +District A,04/04/2026,6,2,,9,f,21/09/2025,,6.41,6.5,65.7,n +District A,04/04/2026,4,4,,2,f,09/02/2025,,13.77,6.4,63,n +District A,05/04/2026,9,1,,1,m,02/09/2025,,7.06,7.2,67,n +District A,05/04/2026,9,1,,2,m,06/05/2025,,10.97,6.9,67,n +District A,05/04/2026,12,4,,2,m,05/05/2025,,11.01,7.4,72.5,n +District A,05/04/2026,12,4,,14,f,11/08/2025,,7.79,5.8,65,n +District A,05/04/2026,12,4,,16,m,09/03/2025,,12.88,5.5,65,n +District A,05/04/2026,12,4,,19,m,07/03/2025,,12.94,5.9,65.3,n +District A,06/04/2026,14,2,,5,f,10/09/2025,,6.83,6.5,64,n +District A,06/04/2026,14,2,,14,f,22/03/2025,,12.48,5,65.2,n +District A,06/04/2026,16,4,,2,m,07/02/2025,,13.9,10.1,73.5,n +District A,06/04/2026,16,4,,6,f,10/04/2025,,11.86,9.1,78.5,n +District A,06/04/2026,16,4,,10,f,03/12/2022,,40.08,13.8,90,n +District A,06/04/2026,16,4,,10,f,03/05/2025,,11.1,7.3,77.2,n +District A,06/04/2026,16,4,,14,m,06/08/2025,,7.98,8,70,n +District A,07/04/2026,20,4,,2,f,10/07/2025,,8.9,6.1,65.7,n +District A,07/04/2026,20,4,,6,f,05/02/2025,,14,6.9,65.9,n +District A,07/04/2026,20,4,,14,f,10/07/2025,,8.9,5.6,65.5,n +District A,08/04/2026,24,4,,2,f,12/07/2025,,8.87,7.3,70.4,n +District A,08/04/2026,24,4,,8,f,10/09/2025,,6.9,7.5,68.4,n +District A,08/04/2026,24,4,,10,m,04/08/2025,,8.11,6.7,66.6,n +District A,08/04/2026,24,4,,12,m,06/07/2025,,9.07,5.6,65.1,n +District A,09/04/2026,28,4,,4,f,07/04/2025,,12.06,7.8,74.5,n +District A,09/04/2026,28,4,,9,f,12/07/2025,,8.9,5.3,66.3,n +District A,09/04/2026,28,4,,16,m,10/06/2025,,9.95,6.5,69,n +District A,09/04/2026,28,4,,17,m,13/09/2025,,6.83,4.9,60.1,n +District A,10/04/2026,29,1,,5,f,04/08/2025,,8.18,6.3,64.4,n +District A,10/04/2026,32,4,,2,m,04/04/2025,,12.19,7.3,70.5,n +District A,10/04/2026,32,4,,8,f,08/04/2025,,12.06,5.3,66.5,n +District A,10/04/2026,32,4,,14,m,11/06/2025,,9.95,6.7,69.5,n +District A,11/04/2026,33,1,,17,f,27/08/2025,,7.46,6,63.6,n \ No newline at end of file diff --git a/tests/testthat/test-module-prevalence.R b/tests/testthat/test-module-prevalence.R index b15e165..6133d3c 100644 --- a/tests/testthat/test-module-prevalence.R +++ b/tests/testthat/test-module-prevalence.R @@ -69,6 +69,9 @@ testthat::test_that(desc = "Module works well to estimate weighted-WFHZ prevalen ### Click on Estime Prevalence button ---- app$click(input = "prevalence-estimate") app$wait_for_value(output = "prevalence-results", timeout = 40000) + #### Donwload results ---- + app$wait_for_idle(timeout = 40000) + results <- app$get_download(output = "prevalence-download_results") ### Capture JavaScript expressions to return results's cols and values ---- js_cols <- "$('#prevalence-results thead th').map(function() @@ -90,6 +93,15 @@ testthat::test_that(desc = "Module works well to estimate weighted-WFHZ prevalen testthat::expect_equal(length(app$get_js(js_cols)[1:19]), 19) testthat::expect_equal(as.numeric(weighted_pop), 292611) testthat::expect_equal(as.numeric(gam_prev), 6.1) + testthat::expect_equal( + object = basename(results), + paste0( + "mwana-amn-prevalence-survey-wfhz_", + Sys.Date(), + ".xlsx", + sep = "" + ) + ) ### Stop the app ---- app$stop() @@ -161,6 +173,9 @@ testthat::test_that(desc = "Module works well to estimate unweighted-WFHZ preval ### Click on Estime Prevalence button ---- app$click(input = "prevalence-estimate") app$wait_for_value(output = "prevalence-results", timeout = 40000) + #### Donwload results ---- + app$wait_for_idle(timeout = 40000) + results <- app$get_download(output = "prevalence-download_results") ### Capture JavaScript expressions to return results's cols and values ---- js_cols <- "$('#prevalence-results thead th').map(function() @@ -178,6 +193,15 @@ testthat::test_that(desc = "Module works well to estimate unweighted-WFHZ preval testthat::expect_equal(length(app$get_js(js_cols)[1:19]), 19) testthat::expect_equal(as.numeric(pop), 280) testthat::expect_equal(as.numeric(gam_prev), 6.1) + testthat::expect_equal( + object = basename(results), + paste0( + "mwana-amn-prevalence-survey-wfhz_", + Sys.Date(), + ".xlsx", + sep = "" + ) + ) ### Stop the app ---- app$stop() @@ -254,6 +278,9 @@ testthat::test_that(desc = "Module works well to estimate weighted-MUAC prevalen ### Click on Estime Prevalence button ---- app$click(input = "prevalence-estimate") app$wait_for_value(output = "prevalence-results", timeout = 40000) + #### Donwload results ---- + app$wait_for_idle(timeout = 40000) + results <- app$get_download(output = "prevalence-download_results") ### Capture JavaScript expressions to return results's cols and values ---- js_cols <- "$('#prevalence-results thead th').map(function() @@ -283,6 +310,15 @@ testthat::test_that(desc = "Module works well to estimate weighted-MUAC prevalen testthat::expect_equal(length(app$get_js(js_cols)[1:19]), 19) testthat::expect_equal(as.numeric(prev[2]), 7.7) # GAM testthat::expect_equal(as.numeric(weighted_pop), 307395) + testthat::expect_equal( + object = basename(results), + paste0( + "mwana-amn-prevalence-survey-muac_", + Sys.Date(), + ".xlsx", + sep = "" + ) + ) ### Stop the app ---- app$stop() @@ -359,6 +395,9 @@ testthat::test_that(desc = "Module works well to estimate unweighted-MUAC preval ### Click on Estime Prevalence button ---- app$click(input = "prevalence-estimate") app$wait_for_value(output = "prevalence-results", timeout = 40000) + #### Donwload results ---- + app$wait_for_idle(timeout = 40000) + results <- app$get_download(output = "prevalence-download_results") ### Capture JavaScript expressions to return results's cols and values ---- js_cols <- "$('#prevalence-results thead th').map(function() @@ -384,6 +423,15 @@ testthat::test_that(desc = "Module works well to estimate unweighted-MUAC preval testthat::expect_equal(length(app$get_js(js_cols)[1:19]), 19) testthat::expect_equal(as.numeric(prev), 8.0) # GAM testthat::expect_equal(as.numeric(pop), 300) + testthat::expect_equal( + object = basename(results), + paste0( + "mwana-amn-prevalence-survey-muac_", + Sys.Date(), + ".xlsx", + sep = "" + ) + ) ### Stop the app ---- app$stop() @@ -460,6 +508,9 @@ testthat::test_that(desc = "Module works well to estimate weighted-combined prev ### Click on Estime Prevalence button ---- app$click(input = "prevalence-estimate") app$wait_for_value(output = "prevalence-results", timeout = 40000) + #### Donwload results ---- + app$wait_for_idle(timeout = 40000) + results <- app$get_download(output = "prevalence-download_results") ### Capture JavaScript expressions to return results's cols and values ---- js_cols <- "$('#prevalence-results thead th').map(function() @@ -481,6 +532,15 @@ testthat::test_that(desc = "Module works well to estimate weighted-combined prev testthat::expect_equal(length(app$get_js(js_cols)[1:19]), 19) testthat::expect_equal(as.numeric(prev[2]), 10.8) # GAM testthat::expect_equal(as.numeric(weighted_pop), 288534) + testthat::expect_equal( + object = basename(results), + paste0( + "mwana-amn-prevalence-survey-combined_", + Sys.Date(), + ".xlsx", + sep = "" + ) + ) ### Stop the app ---- app$stop() @@ -557,6 +617,9 @@ testthat::test_that(desc = "Module works well to estimate unweighted-combined pr ### Click on Estime Prevalence button ---- app$click(input = "prevalence-estimate") app$wait_for_value(output = "prevalence-results", timeout = 40000) + #### Donwload results ---- + app$wait_for_idle(timeout = 40000) + results <- app$get_download(output = "prevalence-download_results") ### Capture JavaScript expressions to return results's cols and values ---- js_cols <- "$('#prevalence-results thead th').map(function() @@ -574,6 +637,15 @@ testthat::test_that(desc = "Module works well to estimate unweighted-combined pr testthat::expect_equal(length(app$get_js(js_cols)[1:19]), 19) testthat::expect_equal(as.numeric(prev), 10.5) # GAM testthat::expect_equal(as.numeric(pop), 276) + testthat::expect_equal( + object = basename(results), + paste0( + "mwana-amn-prevalence-survey-combined_", + Sys.Date(), + ".xlsx", + sep = "" + ) + ) ### Stop the app ---- app$stop() @@ -656,6 +728,9 @@ testthat::test_that(desc = "Module works well to estimate prevalence from screen ### Click on Estime Prevalence button ---- app$click(input = "prevalence-estimate") app$wait_for_value(output = "prevalence-results", timeout = 40000) + #### Donwload results ---- + app$wait_for_idle(timeout = 40000) + results <- app$get_download(output = "prevalence-download_results") ### Capture JavaScript expressions to return results's cols and values ---- js_cols <- "$('#prevalence-results thead th').map(function() @@ -685,6 +760,15 @@ testthat::test_that(desc = "Module works well to estimate prevalence from screen testthat::expect_equal(as.numeric(prev_unit_a)[2], 1.2) # SAM testthat::expect_equal(as.numeric(prev_unit_a)[3], 5.3) # MAM testthat::expect_equal(as.numeric(prev_unit_b), 12.4) # Age-weighted GAM + testthat::expect_equal( + object = basename(results), + paste0( + "mwana-amn-prevalence-screening-age-avail_", + Sys.Date(), + ".xlsx", + sep = "" + ) + ) ### Stop the app ---- app$stop() @@ -767,6 +851,9 @@ testthat::test_that(desc = "Prevalence tab works as expected when age is given i app$click(input = "prevalence-estimate") #### Wait until output has been rendered ---- app$wait_for_value(output = "prevalence-results", timeout = 40000) + #### Donwload results ---- + app$wait_for_idle(timeout = 40000) + results <- app$get_download(output = "prevalence-download_results") ### Capture JavaScript expressions to return results's cols and values ---- js_cols <- "$('#prevalence-results thead th').map(function() @@ -796,6 +883,15 @@ testthat::test_that(desc = "Prevalence tab works as expected when age is given i testthat::expect_equal(as.numeric(prev_unit_a)[2], 1.1) # SAM testthat::expect_equal(as.numeric(prev_unit_a)[3], 5.2) # MAM testthat::expect_equal(as.numeric(prev_unit_b), 12.6) # Age-weighted GAM + testthat::expect_equal( + object = basename(results), + paste0( + "mwana-amn-prevalence-screening-age-notavail_", + Sys.Date(), + ".xlsx", + sep = "" + ) + ) ### Stop the app ---- app$stop()