-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into improve-autoplotpop_data-error-communication
- Loading branch information
Showing
18 changed files
with
273 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Type: Package | ||
Package: serocalculator | ||
Title: Estimating Infection Rates from Serological Data | ||
Version: 1.2.0.9015 | ||
Version: 1.2.0.9016 | ||
Authors@R: c( | ||
person("Peter", "Teunis", , "[email protected]", role = c("aut", "cph"), | ||
comment = "Author of the method and original code."), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#' Load noise parameters | ||
#' | ||
#' @param data a [data.frame()] or [tibble::tbl_df] | ||
#' @param antigen_isos [character()] vector of antigen isotypes | ||
#' to be used in analyses | ||
#' | ||
#' @returns a `noise_params` object (a [tibble::tbl_df] with | ||
#' extra attribute `antigen_isos`) | ||
#' @export | ||
#' @examples | ||
#' library(magrittr) | ||
#' noise_data <- | ||
#' "https://osf.io/download//hqy4v/" %>% | ||
#' readr::read_rds() %>% | ||
#' as_noise_params() | ||
#' | ||
#' print(noise_data) | ||
#' | ||
as_noise_params <- function(data, antigen_isos = NULL) { | ||
if (!is.data.frame(data)) { | ||
cli::cli_abort( | ||
class = "not data.frame", | ||
message = c( | ||
"Can't convert {.arg data} to {.cls noise_params}.", | ||
paste( | ||
"x" = "{.arg data} must be a {.cls data.frame}", | ||
"(or a subclass of {.cls data.frame})." | ||
), | ||
"i" = "You have supplied a {.cls {class(data)}}." | ||
) | ||
) | ||
} | ||
|
||
noise_data <- data %>% tibble::as_tibble() | ||
|
||
# Define noise columns | ||
noise_cols <- c("antigen_iso", "y.low", "eps", "nu", "y.high") | ||
|
||
# Get any missing columns | ||
missing_cols <- setdiff(x = noise_cols, y = names(data)) | ||
|
||
if (length(missing_cols) > 0) { | ||
cli::cli_abort( | ||
class = "not noise_params", | ||
message = c( | ||
"Can't convert {.arg data} to {.cls noise_params}.", | ||
"i" = paste( | ||
"The column{?s}: {.strong {.var {missing_cols}}}", | ||
"{?is/are} missing." | ||
) | ||
) | ||
) | ||
} | ||
|
||
# Assign noise_params class | ||
class(noise_data) <- c("noise_params", class(noise_data)) | ||
|
||
# Handle antigen_isos | ||
if (is.null(antigen_isos)) { | ||
antigen_isos <- unique(noise_data$antigen_iso) | ||
} else { | ||
missing_antigen <- setdiff(antigen_isos, unique(noise_data$antigen_iso)) | ||
|
||
if (length(missing_antigen) > 0) { | ||
cli::cli_abort( | ||
class = "missing-antigen", | ||
message = c( | ||
"x" = "Can't convert {.var data} to {.cls noise_params}.", | ||
"i" = paste( | ||
"The antigen type{?s} {.str {missing_antigen}}", | ||
"{?is/are} missing in {.var data}." | ||
) | ||
) | ||
) | ||
} | ||
} | ||
|
||
# Assign antigen attribute | ||
attr(noise_data, "antigen_isos") <- antigen_isos | ||
|
||
return(noise_data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ template: | |
bootstrap: 5 | ||
light-switch: true | ||
|
||
bibliography: vignettes/references.bib |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# `as_noise_params()` produces expected results | ||
|
||
Code | ||
test_data | ||
Output | ||
# A tibble: 16 x 7 | ||
antigen_iso Country y.low eps nu y.high Lab | ||
<chr> <fct> <dbl> <dbl> <dbl> <dbl> <fct> | ||
1 HlyE_IgA Bangladesh 0.376 0.280 2.60 5000000 CHRF | ||
2 HlyE_IgA Ghana 0.179 0.240 2.60 5000000 MGH | ||
3 HlyE_IgA Nepal 0.853 0.238 2.60 5000000 DH | ||
4 HlyE_IgA Pakistan 0.508 0.279 2.60 5000000 AKU | ||
5 HlyE_IgG Bangladesh 0.787 0.306 2.36 5000000 CHRF | ||
6 HlyE_IgG Ghana 0.645 0.164 2.36 5000000 MGH | ||
7 HlyE_IgG Nepal 1.89 0.128 2.36 5000000 DH | ||
8 HlyE_IgG Pakistan 1.59 0.146 2.36 5000000 AKU | ||
9 LPS_IgA Bangladesh 0.660 0.299 2.14 5000000 CHRF | ||
10 LPS_IgA Ghana 0.861 0.163 2.14 5000000 MGH | ||
11 LPS_IgA Nepal 1.79 0.115 2.14 5000000 DH | ||
12 LPS_IgA Pakistan 5.13 0.246 2.14 5000000 AKU | ||
13 LPS_IgG Bangladesh 0.992 0.298 3.24 5000000 CHRF | ||
14 LPS_IgG Ghana 0.885 0.195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AAMYW50 | ||
aWdlbl9pc29zAAAAEAAAAAQABAAJAAAACEhseUVfSWdBAAQACQAAAAhIbHlFX0lnRwAEAAkA | ||
AAAHTFBTX0lnQQAEAAkAAAAHTFBTX0lnRwAAAP4= | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
test_that("`as_noise_params()` produces an error | ||
when non-noise data is provided", { | ||
library(magrittr) | ||
expect_error( | ||
object = noise_data <- | ||
"https://osf.io/download//n6cp3/" %>% # pop data | ||
readr::read_rds() %>% | ||
as_noise_params(), | ||
class = "not noise_params" | ||
) | ||
}) | ||
|
||
test_that("`as_noise_params()` produces expected results", { | ||
library(dplyr) | ||
test_data <- "https://osf.io/download//hqy4v/" %>% # noise data | ||
readr::read_rds() %>% | ||
as_noise_params() | ||
|
||
expect_snapshot(test_data) | ||
|
||
expect_snapshot_value( | ||
x = test_data, | ||
style = "serialize" | ||
) | ||
}) | ||
|
||
test_that("`as_noise_params()` produces error when | ||
wrong antigen_iso is provided", { | ||
library(dplyr) | ||
|
||
expect_error( | ||
object = "https://osf.io/download//hqy4v/" %>% # noise data | ||
readr::read_rds() %>% | ||
as_noise_params(antigen_iso = "HlyE_IgB"), | ||
class = "missing-antigen" | ||
) | ||
}) | ||
|
||
test_that("`as_noise_params()` produces error when | ||
non-data frame is provided", { | ||
library(dplyr) | ||
|
||
expect_error( | ||
object = "a string sample" %>% # random string | ||
as_noise_params(), | ||
class = "not data.frame" | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,5 @@ methodology_files | |
*_files/ | ||
*.pptx | ||
*.docx | ||
|
||
/.quarto/ | ||
*.rmarkdown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.