Skip to content

Commit

Permalink
Add comments on complex input checks
Browse files Browse the repository at this point in the history
  • Loading branch information
pratikunterwegs committed Mar 12, 2024
1 parent 8abb8cd commit 51cccaf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
24 changes: 13 additions & 11 deletions R/model_default.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,8 @@ model_default <- function(population,
# take parameter names here as names(DT) updates by reference!
param_names <- names(params)

# Check if `intervention` is a list of interventions or a list-of-lists
# and convert to a list for a data.table list column. NULL is allowed;
# Check if `vaccination` is a single vaccination or a list
# and convert to a list for a data.table list column
# Check if `intervention` is a single intervention set or a list of such sets
# NULL is allowed;
is_lofints <- checkmate::test_list(
intervention, "intervention",
all.missing = FALSE, null.ok = TRUE
Expand All @@ -168,21 +166,25 @@ model_default <- function(population,
is_lofls <- checkmate::test_list(
intervention,
types = c("list", "null"), all.missing = FALSE
) && all(
vapply(
unlist(intervention, recursive = FALSE),
FUN = function(x) {
is_intervention(x) || is.null(x)
}, TRUE
) &&
# Check that all elements of intervention sets are either `<intervention>`
# or NULL
all(
vapply(
unlist(intervention, recursive = FALSE),
FUN = function(x) {
is_intervention(x) || is.null(x)
}, TRUE
)
)
)

# Check if parameters can be recycled;
stopifnot(
"All parameters must be of the same length, or must have length 1" =
.test_recyclable(params),
"`intervention` must be a list of <intervention>s or a list of such lists" =
is_lofints || is_lofls,
# Check if `vaccination` is a single vaccination, NULL, or a list
"`vaccination` must be a <vaccination> or a list of <vaccination>s" =
is_vaccination(vaccination) || checkmate::test_list(
vaccination,
Expand Down
24 changes: 13 additions & 11 deletions R/model_vacamole.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,8 @@ model_vacamole <- function(population,
# take parameter names here as names(DT) updates by reference!
param_names <- names(params)

# Check if `intervention` is a list of interventions or a list-of-lists
# and convert to a list for a data.table list column. NULL is allowed;
# Check if `vaccination` is a single vaccination or a list
# and convert to a list for a data.table list column
# Check if `intervention` is a single intervention set or a list of such sets
# NULL is allowed;
is_lofints <- checkmate::test_list(
intervention, "intervention",
all.missing = FALSE, null.ok = TRUE
Expand All @@ -208,21 +206,25 @@ model_vacamole <- function(population,
is_lofls <- checkmate::test_list(
intervention,
types = c("list", "null"), all.missing = FALSE
) && all(
vapply(
unlist(intervention, recursive = FALSE),
FUN = function(x) {
is_intervention(x) || is.null(x)
}, TRUE
) &&
# Check that all elements of intervention sets are either `<intervention>`
# or NULL
all(
vapply(
unlist(intervention, recursive = FALSE),
FUN = function(x) {
is_intervention(x) || is.null(x)
}, TRUE
)
)
)

# Check if parameters can be recycled;
stopifnot(
"All parameters must be of the same length, or must have length 1" =
.test_recyclable(params),
"`intervention` must be a list of <intervention>s or a list of such lists" =
is_lofints || is_lofls,
# Check if `vaccination` is a single vaccination, NULL, or a list
"`vaccination` must be a <vaccination> or a list of <vaccination>s" =
is_vaccination(vaccination) || checkmate::test_list(
vaccination,
Expand Down

0 comments on commit 51cccaf

Please sign in to comment.