From e8bbbfa99b3207d1663fc5c27c5c3a4624f0e827 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Thu, 4 Jan 2024 14:30:53 +0000 Subject: [PATCH] reduce cyclocomp of delay distribution input checking --- R/sim_contacts.R | 5 ++--- R/sim_linelist.R | 6 +++--- R/sim_outbreak.R | 9 ++++----- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/R/sim_contacts.R b/R/sim_contacts.R index d3b7ef28..b453d771 100644 --- a/R/sim_contacts.R +++ b/R/sim_contacts.R @@ -51,9 +51,8 @@ sim_contacts <- function(R, # check and convert distribution to func if needed before .check_sim_input() stopifnot( "Input delay distributions need to be either functions or " = - (is.function(serial_interval) || inherits(serial_interval, "epidist")) && - (is.function(contact_distribution) || - inherits(contact_distribution, "epidist")) + inherits(serial_interval, c("function", "epidist")) && + inherits(contact_distribution, c("function", "epidist")) ) serial_interval <- as.function(serial_interval, func_type = "generate") contact_distribution <- as.function( diff --git a/R/sim_linelist.R b/R/sim_linelist.R index d3dc7b99..88addc35 100644 --- a/R/sim_linelist.R +++ b/R/sim_linelist.R @@ -137,9 +137,9 @@ sim_linelist <- function(R, # check and convert distribution to func if needed before .check_sim_input() stopifnot( "Input delay distributions need to be either functions or " = - (is.function(serial_interval) || inherits(serial_interval, "epidist")) && - (is.function(onset_to_hosp) || inherits(onset_to_hosp, "epidist")) && - (is.function(onset_to_death) || inherits(onset_to_death, "epidist")) + inherits(serial_interval, c("function", "epidist")) && + inherits(onset_to_hosp, c("function", "epidist")) && + inherits(onset_to_death, c("function", "epidist")) ) serial_interval <- as.function(serial_interval, func_type = "generate") onset_to_hosp <- as.function(onset_to_hosp, func_type = "generate") diff --git a/R/sim_outbreak.R b/R/sim_outbreak.R index 6d496a5d..57213e3a 100644 --- a/R/sim_outbreak.R +++ b/R/sim_outbreak.R @@ -80,11 +80,10 @@ sim_outbreak <- function(R, # check and convert distribution to func if needed before .check_sim_input() stopifnot( "Input delay distributions need to be either functions or " = - (is.function(serial_interval) || inherits(serial_interval, "epidist")) && - (is.function(onset_to_hosp) || inherits(onset_to_hosp, "epidist")) && - (is.function(onset_to_death) || inherits(onset_to_death, "epidist")) && - (is.function(contact_distribution) || - inherits(contact_distribution, "epidist")) + inherits(serial_interval, c("function", "epidist")) && + inherits(onset_to_hosp, c("function", "epidist")) && + inherits(onset_to_death, c("function", "epidist")) && + inherits(contact_distribution, c("function", "epidist")) ) serial_interval <- as.function(serial_interval, func_type = "generate") onset_to_hosp <- as.function(onset_to_hosp, func_type = "generate")