Skip to content

Commit

Permalink
improve error msg if elements are missing in assert_epiparameter
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwlambert committed Aug 12, 2024
1 parent 143d6ab commit cdf7356
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions R/epiparameter.R
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,19 @@ assert_epiparameter <- function(x) {
stop("Object should be of class epiparameter", call. = FALSE)
}

list_names <- c(
"disease", "pathogen", "epi_dist", "prob_dist", "uncertainty",
"summary_stats", "citation", "metadata", "method_assess", "notes"
)
missing_list_names <- list_names[!list_names %in% attributes(x)$names]
if (length(missing_list_names > 0)) {
stop(
"Object is missing ", toString(missing_list_names), call. = FALSE
)
}

# check for class invariants
stopifnot(
"epiparameter object does not contain the correct attributes" =
c(
"disease", "epi_dist", "prob_dist", "uncertainty", "summary_stats",
"citation", "metadata", "method_assess", "notes"
) %in%
attributes(x)$names,
"epiparameter must contain a disease (single character string)" =
checkmate::test_string(x$disease),
"epiparameter must contain an epidemiological distribution" =
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-epiparameter.R
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ test_that("assert_epiparameter catches class faults when expected", {

expect_error(
assert_epiparameter(epiparameter_obj),
regexp = "epiparameter object does not contain the correct attributes"
regexp = "Object is missing disease"
)

epiparameter_obj <- new_epiparameter(
Expand Down

0 comments on commit cdf7356

Please sign in to comment.