From 519bc3c7ecd67b3c17fc1f8c7b9609624b830970 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 11 Dec 2023 10:08:58 +0000 Subject: [PATCH] catch missing dependencies --- DESCRIPTION | 9 ++++++--- NAMESPACE | 1 + R/fitting-and-postprocessing.R | 1 + R/models.R | 6 ++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8ca131396..7b188c601 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,10 +23,13 @@ Imports: cmdstanr, data.table, ggplot2, + posterior, purrr -Remotes: - stan-dev/cmdstanr, - Rdatatable/data.table Suggests: + epinowcast, testthat (>= 3.0.0) +Remotes: + stan-dev/cmdstanr, + Rdatatable/data.table, + epinowcast/epinowcast Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index bcf83cf6c..079f428fb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -51,3 +51,4 @@ import(brms) import(cmdstanr) import(data.table) import(ggplot2) +importFrom(posterior,as_draws_df) diff --git a/R/fitting-and-postprocessing.R b/R/fitting-and-postprocessing.R index a96cbe36e..bd26eff72 100644 --- a/R/fitting-and-postprocessing.R +++ b/R/fitting-and-postprocessing.R @@ -133,6 +133,7 @@ add_natural_scale_mean_sd <- function(dt) { #' Extract posterior samples for a lognormal brms model #' @export +#' @importFrom posterior as_draws_df extract_lognormal_draws <- function( data, id_vars, from_dt = FALSE ) { diff --git a/R/models.R b/R/models.R index 940d7b3ee..7a212f7e2 100644 --- a/R/models.R +++ b/R/models.R @@ -427,6 +427,12 @@ epinowcast_delay <- function(formula = ~ 1, data, by = c(), sampler = epinowcast::enw_sample, with_epinowcast_output = TRUE, ...) { + # check if the epinowcast package is installed and error if not + if (!requireNamespace("epinowcast", quietly = TRUE)) { + stop( + "epinowcast is not installed. Please install it to use this function" + ) + } data_as_counts <- data |> data.table::as.data.table() |> DT(, .(new_confirm = .N), by = c("ptime_daily", "stime_daily", by)) |>