Skip to content

Commit

Permalink
added onset_to_recovery to as_function, WIP #36
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwlambert committed Apr 5, 2024
1 parent 4fd9b0d commit db3c737
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ is_na <- function(x) {
#'
#' @param x A named list containing either `<epidist>`, `function` or `NA`.
#' Named list elements are: `"contact_distribution"`, `"infect_period"`,
#' `"onset_to_hosp"`, `"onset_to_death"`.
#' `"onset_to_hosp"`, `"onset_to_death"`, `"onset_to_recovery".`
#'
#' @return A list of `function`s.
#' @keywords internal
Expand All @@ -112,7 +112,8 @@ as_function <- function(x) {
"Input delay distributions need to be either functions or <epidist>" =
inherits(x$contact_distribution, c("function", "epidist")) &&
inherits(x$infect_period, c("function", "epidist")),
"onset_to_hosp and onset_to_death need to be a function, <epidist> or NA" =
"onset_to_hosp, onset_to_death and onset_to_recovery need to be a function,
<epidist> or NA" =
inherits(x$onset_to_hosp, c("function", "epidist")) ||
is_na(x$onset_to_hosp) &&
inherits(x$onset_to_death, c("function", "epidist")) ||
Expand All @@ -134,12 +135,21 @@ as_function <- function(x) {
} else {
onset_to_death <- as.function(x$onset_to_death, func_type = "generate")
}
if (is_na(x$onset_to_recovery)) {
# function to generate NA instead of recovery times
onset_to_recovery <- function(x) rep(NA, times = x)
} else {
onset_to_recovery <- as.function(
x$onset_to_recovery, func_type = "generate"
)
}

# return list of functions
list(
contact_distribution = contact_distribution,
infect_period = infect_period,
onset_to_hosp = onset_to_hosp,
onset_to_death = onset_to_death
onset_to_death = onset_to_death,
onset_to_recovery = onset_to_recovery
)
}
2 changes: 1 addition & 1 deletion man/as_function.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit db3c737

Please sign in to comment.