]> nmode's Git Repositories - Rnaught/blobdiff - R/id.R
Add GitHub action to run 'R CMD check'
[Rnaught] / R / id.R
diff --git a/R/id.R b/R/id.R
index eef66d68a25c9ed1ef5f50092d5709ec51431bfa..c7c28d3f87f0eced67e1df8bfb61476f7b688821 100644 (file)
--- a/R/id.R
+++ b/R/id.R
@@ -24,9 +24,8 @@
 #'
 #' @return An estimate of the basic reproduction number (R0).
 #'
-#' @references
-#' [Fisman et al. (PloS One, 2013)](
-#' https://doi.org/10.1371/journal.pone.0083622)
+#' @references [Fisman et al. (PloS One, 2013)](
+#'   https://doi.org/10.1371/journal.pone.0083622)
 #'
 #' @seealso [idea()] for a similar method.
 #'
 #' # Obtain R0 when the serial distribution has a mean of three days.
 #' id(cases, mu = 3 / 7)
 id <- function(cases, mu) {
+  validate_cases(cases, min_length = 1, min_count = 1)
+  if (!is_real(mu) || mu <= 0) {
+    stop("The serial interval (`mu`) must be a number greater than 0.",
+      call. = FALSE
+    )
+  }
+
   exp(sum((log(cases) * mu) / seq_along(cases)) / length(cases))
 }