Skip to content

Commit

Permalink
deprecate get functions for delay distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk committed Oct 16, 2023
1 parent 8e0bc34 commit ce4b744
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 81 deletions.
45 changes: 29 additions & 16 deletions R/get.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ get_regional_results <- function(regional_output,
#' Get a Literature Distribution
#'
#'
#' @description `r lifecycle::badge("stable")`
#' Search a data frame for a distribution and return it in the format expected
#' by `delay_opts()` and the `generation_time` argument of `epinow` and
#' `estimate_infections`.
#' @description `r lifecycle::badge("deprecated")`
#'
#' This function has been deprecated. Please specify a distribution
#' using `dist_spec` instead
#'
#' @param data A `data.table` in the format of `generation_times`.
#'
Expand All @@ -177,12 +177,13 @@ get_regional_results <- function(regional_output,
#' @return A list defining a distribution
#'
#' @author Sam Abbott
#' @seealso dist_spec
#' @export
#' @examples
#' get_dist(
#' EpiNow2::generation_times, disease = "SARS-CoV-2", source = "ganyani"
#' )
get_dist <- function(data, disease, source, max_value = 14, fixed = FALSE) {
lifecycle::deprecate_warn(
"2.0.0", "get_dist()", "dist_spec()",
"The function will be removed completely in version 2.1.0."
)
target_disease <- disease
target_source <- source
data <- data[disease == target_disease][source == target_source]
Expand All @@ -195,19 +196,25 @@ get_dist <- function(data, disease, source, max_value = 14, fixed = FALSE) {
}
return(do.call(dist_spec, dist))
}
#' Get a Literature Distribution for the Generation Time
#' Get a Literature Distribution for the Generation Time
#'
#' @description `r lifecycle::badge("deprecated")`
#'
#' @description `r lifecycle::badge("stable")`
#' Extracts a literature distribution from `generation_times`.
#' This function has been deprecated. Please specify a distribution
#' using `dist_spec` instead
#'
#' @inheritParams get_dist
#' @inherit get_dist
#' @export
#' @seealso dist_spec
#' @author Sam Abbott
#' @examples
#' get_generation_time(disease = "SARS-CoV-2", source = "ganyani")
get_generation_time <- function(disease, source, max_value = 14,
fixed = FALSE) {
lifecycle::deprecate_warn(
"2.0.0", "get_generation_time()", "dist_spec()",
"The function will be removed completely in version 2.1.0."
)
dist <- get_dist(EpiNow2::generation_times,
disease = disease, source = source,
max_value = max_value, fixed = fixed
Expand All @@ -217,17 +224,23 @@ get_generation_time <- function(disease, source, max_value = 14,
}
#' Get a Literature Distribution for the Incubation Period
#'
#' @description `r lifecycle::badge("stable")`
#' Extracts a literature distribution from `incubation_periods`.
#' @description `r lifecycle::badge("deprecated")`
#'
#' Extracts a literature distribution from `generation_times`.
#' This function has been deprecated. Please specify a distribution
#' using `dist_spec` instead
#'
#' @inheritParams get_dist
#' @inherit get_dist
#' @author Sam Abbott
#' @export
#' @examples
#' get_incubation_period(disease = "SARS-CoV-2", source = "lauer")
#' @seealso dist_spec
get_incubation_period <- function(disease, source, max_value = 14,
fixed = FALSE) {
lifecycle::deprecate_warn(
"2.0.0", "get_incubation_period()", "dist_spec()",
"The function will be removed completely in version 2.1.0."
)
dist <- get_dist(EpiNow2::incubation_periods,
disease = disease, source = source,
max_value = max_value, fixed = fixed
Expand Down
10 changes: 3 additions & 7 deletions R/opts.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#' Generation Time Distribution Options
#'
#' @description `r lifecycle::badge("stable")`
#' Returns generation time parameters in a format for lower level model use. The
#' generation time can either be given as a \code{disease} and \code{source} to
#' be passed to [get_generation_time], or as parameters of a distribution to be
#' passed to [dist_spec].
#' Returns generation time parameters in a format for lower level model use.
#'
#' @param dist A delay distribution or series of delay distributions generated
#' using [dist_spec()] or [get_generation_time()]. If no distribution is given
#' using [dist_spec()]. If no distribution is given
#' a fixed generation time of 1 will be assumed.
#'
#' @param ... deprecated; use `dist` instead
Expand Down Expand Up @@ -89,8 +86,7 @@ generation_time_opts <- function(dist = dist_spec(mean = 1), ...,
if (deprecated_options_given) {
warning(
"The generation time distribution must be given to ",
"`generation_time_opts` using a call to either ",
"`dist_spec` or `get_generation_time`. ",
"`generation_time_opts` using a call to `dist_spec`. ",
"This behaviour has changed from previous versions of `EpiNow2` and ",
"any code using it may need to be updated as any other ways of ",
"specifying the generation time are deprecated and will be removed in ",
Expand Down
7 changes: 2 additions & 5 deletions man/generation_time_opts.Rd

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

14 changes: 6 additions & 8 deletions man/get_dist.Rd

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

9 changes: 6 additions & 3 deletions man/get_generation_time.Rd

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

11 changes: 7 additions & 4 deletions man/get_incubation_period.Rd

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

41 changes: 18 additions & 23 deletions tests/testthat/test-delays.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,6 @@ test_that("generation times can be specified in different ways", {
), digits = 2),
c(0.02, 0.11, 0.22, 0.30, 0.35)
)
expect_equal(
round(test_stan_delays(
generation_time = generation_time_opts(
get_generation_time(
disease = "SARS-CoV-2", source = "ganyani",
max = 9, fixed = TRUE
)
),
params = delay_params
), digits = 2),
c(0.18, 0.20, 0.17, 0.13, 0.10, 0.07, 0.05, 0.04, 0.03, 0.02)
)
expect_equal(
round(test_stan_delays(
generation_time = generation_time_opts(
get_generation_time(
disease = "SARS-CoV-2", source = "ganyani", max = 10
)
),
params = delay_params
), digits = 2),
c(3.64, 0.71, 3.08, 0.77, 10.00)
)
})

test_that("delay parameters can be specified in different ways", {
Expand Down Expand Up @@ -136,4 +113,22 @@ test_that("deprecated arguments are caught", {
params = delay_params
), "deprecated"
)
expect_warning(
test_stan_delays(
generation_time = generation_time_opts(
get_generation_time(
disease = "SARS-CoV-2", source = "ganyani",
)
),
), "deprecated"
)
expect_warning(
test_stan_delays(
delays = delay_opts(
get_incubation_period(
disease = "SARS-CoV-2", source = "lauer"
)
),
), "deprecated"
)
})
19 changes: 4 additions & 15 deletions tests/testthat/test-get_dist.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
test_that("get_dist returns distributional definition data in the format expected by EpiNow2", {
test_that("get_dist is deprecated", {
data <- data.table::data.table(mean = 1, mean_sd = 1, sd = 1, sd_sd = 1, source = "test", disease = "test", dist = "gamma")
dist <- get_dist(data, disease = "test", source = "test")
expect_equal(
dist[c("mean_mean", "mean_sd", "sd_mean", "sd_sd", "max")],
list(mean_mean = array(1), mean_sd = array(1),
sd_mean = array(1), sd_sd = array(1), max = array(14))
)
})

test_that("get_dist returns distributional definition data in the format expected by EpiNow2 with no uncertainty", {
data <- data.table::data.table(mean = 1, mean_sd = 1, sd = 1, sd_sd = 1, source = "test", disease = "test", dist = "lognormal")
dist <- get_dist(data, disease = "test", source = "test", fixed = TRUE)
expect_equal(
round(dist$np_pmf[1:7], digits = 2),
array(c(0.17, 0.23, 0.17, 0.12, 0.08, 0.06, 0.04))
expect_warning(
get_dist(data, disease = "test", source = "test"),
"deprecated"
)
})

0 comments on commit ce4b744

Please sign in to comment.