From b5063cb4717718976022052d8e3e7abcda6f4131 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 19 Dec 2024 17:04:28 +0000 Subject: [PATCH] change over opts and create interface --- R/create.R | 2 +- R/opts.R | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/R/create.R b/R/create.R index 789bbb444..88da040c8 100644 --- a/R/create.R +++ b/R/create.R @@ -280,7 +280,7 @@ create_rt_data <- function(rt = rt_opts(), breakpoints = NULL, breakpoints = breakpoints, future_fixed = as.numeric(future_rt$fixed), fixed_from = future_rt$from, - pop = rt$pop, + pop = as.integer(rt$pop != Fixed(0)), stationary = as.numeric(rt$gp_on == "R0"), future_time = horizon - future_rt$from ) diff --git a/R/opts.R b/R/opts.R index 613a6452f..7ed86568d 100644 --- a/R/opts.R +++ b/R/opts.R @@ -320,9 +320,9 @@ trunc_opts <- function(dist = Fixed(0), default_cdf_cutoff = 0.001, #' conservative estimate of break point changes (alter this by setting #' `gp = NULL`). #' -#' @param pop Integer, defaults to 0. Susceptible population initially present. -#' Used to adjust Rt estimates when otherwise fixed based on the proportion of -#' the population that is susceptible. When set to 0 no population adjustment +#' @param pop A `` giving the initial susceptible population size. +#' Used to adjust Rt estimates based on the proportion of the population that +#' is susceptible. Defaults to `Fixed(0)` which means no population adjustment #' is done. #' #' @param gp_on Character string, defaulting to "R_t-1". Indicates how the @@ -354,13 +354,12 @@ rt_opts <- function(prior = LogNormal(mean = 1, sd = 1), use_breakpoints = TRUE, future = "latest", gp_on = c("R_t-1", "R0"), - pop = 0) { + pop = Fixed(0)) { rt <- list( use_rt = use_rt, rw = rw, use_breakpoints = use_breakpoints, future = future, - pop = pop, gp_on = arg_match(gp_on) ) @@ -388,6 +387,17 @@ rt_opts <- function(prior = LogNormal(mean = 1, sd = 1), prior <- LogNormal(mean = prior$mean, sd = prior$sd) } + if (is.numeric(pop)) { + cli_warn( + c( + "!" = "Specifying {.var pop} as a numeric value is deprecated.", + "i" = "Use a {.cls dist_spec} instead, e.g. Fixed({pop})." + ) + ) + pop <- Fixed(pop) + } + rt$pop <- pop + if (rt$use_rt) { rt$prior <- prior } else { @@ -698,7 +708,7 @@ obs_opts <- function(family = c("negbin", "poisson"), cli_abort( c( "!" = "Specifying {.var phi} as a vector of length 2 is deprecated.", - "i" = "Mean and SD should be given as list elements." + "i" = "Use a {.cls dist_spec} instead, e.g. Normal(mean = {phi[1]}, sd = {phi[2]})." ) ) }