diff --git a/NAMESPACE b/NAMESPACE index 3ca6f47d8..b28f13928 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -33,6 +33,7 @@ export(LogNormal) export(NonParametric) export(Normal) export(R_to_growth) +export(add_breakpoints) export(adjust_infection_to_report) export(apply_tolerance) export(backcalc_opts) @@ -64,6 +65,7 @@ export(extract_inits) export(extract_samples) export(extract_stan_param) export(fill_missing) +export(filter_leading_zeros) export(fix_dist) export(fix_parameters) export(forecast_infections) diff --git a/NEWS.md b/NEWS.md index 28df3b2a2..29b8a2ebf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -19,6 +19,10 @@ - A bug was fixed where an internal function for applying a default cdf cutoff failed due to a difference a vector length issue. By @jamesmbaazam in #858 and reviewed by @sbfnk. - All parameters have been changed to the new parameter interface. By @sbfnk in #871 and reviewed by @seabbs. +## Package changes + +- The internal functions `create_clean_reported_cases()` has been broken up into several functions, with relevant ones `filter_leading_zeros()`, `add_breakpoints()` and `apply_zero_threshold()` exposed to the user. By @sbfnk in #884 and reviewed by @seabbs and @jamesmbaazam. + ## Documentation - Brought the docs on `alpha_sd` up to date with the code change from prior PR #853. By @zsusswein in #862 and reviewed by @jamesmbaazam. diff --git a/R/create.R b/R/create.R index ed4524003..ade71b2e4 100644 --- a/R/create.R +++ b/R/create.R @@ -1,5 +1,5 @@ #' Create Clean Reported Cases -#' @description `r lifecycle::badge("stable")` +#' @description `r lifecycle::badge("deprecated")` #' Filters leading zeros, completes dates, and applies an optional threshold at #' which point 0 cases are replaced with a user supplied value (defaults to #' `NA`). @@ -12,16 +12,12 @@ #' number of cases based on the 7-day average. If the average is above this #' threshold then the zero is replaced using `fill`. #' -#' @param fill Numeric, defaults to NA. Value to use to replace NA values or -#' zeroes that are flagged because the 7-day average is above the -#' `zero_threshold`. If the default NA is used then dates with NA values or with -#' 7-day averages above the `zero_threshold` will be skipped in model fitting. -#' If this is set to 0 then the only effect is to replace NA values with 0. +#' @param fill Deprecated; zero dates with 7-day averages above the +#' `zero_threshold` will be skipped in model fitting. #' @param add_breakpoints Logical, defaults to TRUE. Should a breakpoint column #' be added to the data frame if it does not exist. #' #' @inheritParams estimate_infections -#' @importFrom data.table copy merge.data.table setorder setDT frollsum #' @return A cleaned data frame of reported cases #' @keywords internal #' @examples @@ -33,55 +29,15 @@ create_clean_reported_cases <- function(data, horizon = 0, zero_threshold = Inf, fill = NA_integer_, add_breakpoints = TRUE) { - reported_cases <- data.table::setDT(data) - reported_cases_grid <- data.table::copy(reported_cases)[, - .(date = seq(min(date), max(date) + horizon, by = "days")) - ] - - reported_cases <- data.table::merge.data.table( - reported_cases, reported_cases_grid, - by = "date", all.y = TRUE - ) - - if (is.null(reported_cases$breakpoint) && add_breakpoints) { - reported_cases$breakpoint <- 0 + reported_cases <- add_horizon(data, horizon = horizon) + if (add_breakpoints) { + reported_cases <- add_breakpoints(reported_cases) } - if (!is.null(reported_cases$breakpoint)) { - reported_cases[is.na(breakpoint), breakpoint := 0] - } - reported_cases <- data.table::setorder(reported_cases, date) - ## Filter out 0 reported cases from the beginning of the data if (filter_leading_zeros) { - reported_cases <- reported_cases[order(date)][ - date >= min(date[confirm[!is.na(confirm)] > 0]) - ] - } - # Calculate `average_7_day` which for rows with `confirm == 0` - # (the only instance where this is being used) equates to the 7-day - # right-aligned moving average at the previous data point. - reported_cases <- - reported_cases[ - , - `:=`(average_7_day = ( - data.table::frollsum(confirm, n = 8, na.rm = TRUE) - ) / 7 - ) - ] - # Check case counts preceding zero case counts and set to 7 day average if - # average over last 7 days is greater than a threshold - if (!is.infinite(zero_threshold)) { - reported_cases <- reported_cases[ - confirm == 0 & average_7_day > zero_threshold, - confirm := NA_integer_ - ] - } - reported_cases[is.na(confirm), confirm := fill] - reported_cases[, "average_7_day" := NULL] - ## set accumulate to FALSE in added rows - if ("accumulate" %in% colnames(reported_cases)) { - reported_cases[is.na(accumulate), accumulate := FALSE] + reported_cases <- filter_leading_zeros(reported_cases) } - return(reported_cases) + reported_cases <- apply_zero_threshold(reported_cases, zero_threshold) + return(reported_cases[]) } #' Create complete cases diff --git a/R/estimate_infections.R b/R/estimate_infections.R index 1b4fff209..1d5b5f004 100644 --- a/R/estimate_infections.R +++ b/R/estimate_infections.R @@ -140,6 +140,20 @@ estimate_infections <- function(data, "estimate_infections(data)" ) } + if (!missing(filter_leading_zeros)) { + lifecycle::deprecate_warn( + "1.7.0", + "estimate_infections(filter_leading_zeros)", + "filter_leading_zeros()" + ) + } + if (!missing(zero_threshold)) { + lifecycle::deprecate_warn( + "1.7.0", + "estimate_infections(zero_threshold)", + "apply_zero_threshold()" + ) + } # Validate inputs check_reports_valid(data, model = "estimate_infections") assert_class(generation_time, "generation_time_opts") @@ -184,6 +198,19 @@ estimate_infections <- function(data, ) # Fill missing dates reported_cases <- default_fill_missing_obs(data, obs, "confirm") + # Check initial zeros to check for deprecated filter zero functionality + if (filter_leading_zeros && + !is.na(reported_cases[date == min(date), "confirm"]) && + reported_cases[date == min(date), "confirm"] == 0) { + cli_warn(c( + "!" = "Filtering initial zero observations in the data. This + functionality will be removed in future versions of EpiNow2. In order + to retain the default behaviour and filter initial zero observations + use the {.fn filter_leading_zeros()} function on the data before + calling {.fn estimate_infections()}." + )) + } + # Create clean and complete cases reported_cases <- create_clean_reported_cases( reported_cases, horizon, diff --git a/R/estimate_secondary.R b/R/estimate_secondary.R index 13054e956..09b635d7d 100644 --- a/R/estimate_secondary.R +++ b/R/estimate_secondary.R @@ -172,6 +172,20 @@ estimate_secondary <- function(data, "estimate_secondary(data)" ) } + if (!missing(filter_leading_zeros)) { + lifecycle::deprecate_warn( + "1.7.0", + "estimate_secondary(filter_leading_zeros)", + "filter_leading_zeros()" + ) + } + if (!missing(zero_threshold)) { + lifecycle::deprecate_warn( + "1.7.0", + "estimate_secondary(zero_threshold)", + "apply_zero_threshold()" + ) + } # Validate the inputs check_reports_valid(data, model = "estimate_secondary") assert_class(secondary, "secondary_opts") @@ -200,6 +214,16 @@ estimate_secondary <- function(data, secondary_reports_dirty <- reports[, list(date, confirm = secondary, accumulate)] + if (filter_leading_zeros && + !is.na(secondary_reports_dirty[date == min(date), "confirm"]) && + secondary_reports_dirty[date == min(date), "confirm"] == 0) { + cli_warn(c( + "!" = "Filtering initial zero observations in the data. This + functionality will be removed in future versions of EpiNow2. In order + to filter initial zero observations use the {.fn filter_leading_zeros} + function on the data before calling {.fn estimate_secondary}." + )) + } secondary_reports <- create_clean_reported_cases( secondary_reports_dirty, filter_leading_zeros = filter_leading_zeros, diff --git a/R/preprocessing.R b/R/preprocessing.R index a43171bad..913300d7b 100644 --- a/R/preprocessing.R +++ b/R/preprocessing.R @@ -42,7 +42,7 @@ ##' using a data set that has multiple columns of hwich one of them ##' corresponds to observations that are to be processed here. ##' @param by Character vector. Name(s) of any additional column(s) where -##' missing data should be processed separately for each value in the column. +##' data processing should be done separately for each value in the column. ##' This is useful when using data representing e.g. multiple geographies. If ##' NULL (default) no such grouping is done. ##' @return a data.table with an `accumulate` column that indicates whether @@ -177,3 +177,158 @@ default_fill_missing_obs <- function(data, obs, obs_column) { } return(data) } + +##' Add missing values for future dates +##' +##' @param data Data frame with a `date` column. The other columns depend on the +##' model that the data are to be used, e.g. [estimate_infections()] or +##' [estimate_secondary()]. See the documentation there for the expected +##' format. +##' @param accumulate The number of days to accumulate when generating posterior +##' prediction, e.g. 7 for weekly accumulated forecasts. +##' @inheritParams fill_missing +##' @inheritParams estimate_infections +##' @importFrom data.table copy merge.data.table setDT +##' @return A data.table with missing values for future dates +##' @keywords internal +add_horizon <- function(data, horizon, accumulate = 1L, + obs_column = "confirm", by = NULL) { + assert_data_frame(data) + assert_character(obs_column) + assert_character(by, null.ok = TRUE) + assert_names( + colnames(data), + must.include = c("date", by, obs_column) + ) + assert_integerish(horizon, lower = 0) + assert_integerish(accumulate, lower = 1) + assert_date(data$date, any.missing = FALSE) + + reported_cases <- data.table::setDT(data) + if (horizon > 0) { + reported_cases_future <- data.table::copy(reported_cases)[, + .(date = seq(max(date) + 1, max(date) + horizon, by = "days")), + by = by + ] + ## if we accumulate add the column + if (accumulate > 1 || "accumulate" %in% colnames(data)) { + reported_cases_future[, accumulate := TRUE] + ## set accumulation to FALSE where appropriate + if (horizon >= accumulate) { + reported_cases_future[ + as.integer(date - min(date) - 1) %% accumulate == 0, + accumulate := FALSE + ] + } + } + ## fill any missing columns + reported_cases <- rbind( + reported_cases, reported_cases_future, + fill = TRUE + ) + } + return(reported_cases[]) +} + +##' Add breakpoints to certain dates in a data set. +##' +##' @param dates A vector of dates to use as breakpoints. +##' @inheritParams estimate_infections +##' @return A data.table with `breakpoint` set to 1 on each of the specified +##' dates. +##' @export +##' @importFrom data.table setDT +##' @examples +##' reported_cases <- add_breakpoints(example_confirmed, as.Date("2020-03-26")) +add_breakpoints <- function(data, dates = as.Date(character(0))) { + assert_data_frame(data) + assert_names(colnames(data), must.include = "date") + assert_date(dates) + assert_date(data$date, any.missing = FALSE) + reported_cases <- data.table::setDT(data) + if (is.null(reported_cases$breakpoint)) { + reported_cases$breakpoint <- 0 + } + missing_dates <- setdiff(dates, data$date) + if (length(missing_dates) > 0) { + cli_abort("Breakpoint date{?s} not found in data: {.var {missing_dates}}") + } + reported_cases[date %in% dates, breakpoint := 1] + reported_cases[is.na(breakpoint), breakpoint := 0] + return(reported_cases) +} + +##' Filter leading zeros from a data set. +##' +##' @inheritParams estimate_infections +##' @inheritParams fill_missing +##' @return A data.table with leading zeros removed. +##' @export +##' @importFrom data.table setDT +##' @examples +##' cases <- data.frame( +##' date = as.Date("2020-01-01") + 0:10, +##' confirm = c(0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9) +##' ) +##' filter_leading_zeros(cases) +filter_leading_zeros <- function(data, obs_column = "confirm", by = NULL) { + assert_data_frame(data) + assert_character(obs_column) + assert_character(by, null.ok = TRUE) + assert_names( + colnames(data), + must.include = c("date", by, obs_column) + ) + reported_cases <- data.table::setDT(data) + reported_cases <- reported_cases[order(date)][ + date >= min(date[get(obs_column)[!is.na(get(obs_column))] > 0]) + ] + return(reported_cases[]) +} + +##' Convert zero case counts to `NA` (missing) if the 7-day average is above a +##' threshold. +##' +##' This function aims to detect spurious zeroes by comparing the 7-day average +##' of the case counts to a threshold. If the 7-day average is above the +##' threshold, the zero case count is replaced with `NA`. +##' +##' @param threshold Numeric, defaults to `Inf`. Indicates if detected zero +##' cases are meaningful by using a threshold number of cases based on the +##' 7-day average. If the average is above this threshold at the time of a +##' zero observation count then the zero is replaced with a missing (`NA`) +##' count and thus ignored in the likelihood. +##' +##' @inheritParams estimate_infections +##' @inheritParams fill_missing +##' @importFrom data.table setDT frollsum +##' @return A data.table with the zero threshold applied. +apply_zero_threshold <- function(data, threshold = Inf, + obs_column = "confirm") { + assert_data_frame(data) + assert_numeric(threshold) + reported_cases <- data.table::setDT(data) + + # Calculate `average_7_day` which for rows with `confirm == 0` + # (the only instance where this is being used) equates to the 7-day + # right-aligned moving average at the previous data point. + reported_cases <- + reported_cases[ + , + `:=`(average_7_day = ( + data.table::frollsum(get(obs_column), n = 8, na.rm = TRUE) + ) / 7 + ) + ] + # Check case counts preceding zero case counts and set to 7 day average if + # average over last 7 days is greater than a threshold + if (!is.infinite(threshold)) { + reported_cases <- reported_cases[ + get(obs_column) == 0 & average_7_day > threshold, + paste(obs_column) := NA_integer_ + ] + } + reported_cases[is.na(get(obs_column)), paste(obs_column) := NA_integer_] + reported_cases[, "average_7_day" := NULL] + return(reported_cases[]) +} diff --git a/R/utilities.R b/R/utilities.R index 5fb413fc5..3a73bacec 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -442,6 +442,6 @@ globalVariables( "..lowers", "..upper_CrI", "..uppers", "timing", "dataset", "last_confirm", "report_date", "secondary", "id", "conv", "meanlog", "primary", "scaled", "scaling", "sdlog", "lookup", "new_draw", ".draw", "p", "distribution", - "accumulate", "..present" + "accumulate", "..present", "reported_cases" ) ) diff --git a/_pkgdown.yml b/_pkgdown.yml index ae09e56fe..370830c69 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -78,6 +78,13 @@ reference: contents: - contains("_opts") - opts_list + - title: Preprocess data + desc: Functions used for prepropcessing data + contents: + - fill_missing + - add_breakpoints + - filter_leading_zeros + - apply_zero_threshold - title: Summarise Across Regions desc: Functions used for summarising across regions (designed for use with regional_epinow) contents: diff --git a/man/add_breakpoints.Rd b/man/add_breakpoints.Rd new file mode 100644 index 000000000..761d310d9 --- /dev/null +++ b/man/add_breakpoints.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/preprocessing.R +\name{add_breakpoints} +\alias{add_breakpoints} +\title{Add breakpoints to certain dates in a data set.} +\usage{ +add_breakpoints(data, dates = as.Date(character(0))) +} +\arguments{ +\item{data}{A \verb{} of confirmed cases (confirm) by date (date). +\code{confirm} must be numeric and \code{date} must be in date format. Optionally +this can also have a logical \code{accumulate} column which indicates whether +data should be added to the next data point. This is useful when modelling +e.g. weekly incidence data. See also the \code{\link[=fill_missing]{fill_missing()}} function which +helps add the \code{accumulate} column with the desired properties when dealing +with non-daily data. If any accumulation is done this happens after +truncation as specified by the \code{truncation} argument.} + +\item{dates}{A vector of dates to use as breakpoints.} +} +\value{ +A data.table with \code{breakpoint} set to 1 on each of the specified +dates. +} +\description{ +Add breakpoints to certain dates in a data set. +} +\examples{ +reported_cases <- add_breakpoints(example_confirmed, as.Date("2020-03-26")) +} diff --git a/man/add_horizon.Rd b/man/add_horizon.Rd new file mode 100644 index 000000000..ca1ce27cf --- /dev/null +++ b/man/add_horizon.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/preprocessing.R +\name{add_horizon} +\alias{add_horizon} +\title{Add missing values for future dates} +\usage{ +add_horizon(data, horizon, accumulate = 1L, obs_column = "confirm", by = NULL) +} +\arguments{ +\item{data}{Data frame with a \code{date} column. The other columns depend on the +model that the data are to be used, e.g. \code{\link[=estimate_infections]{estimate_infections()}} or +\code{\link[=estimate_secondary]{estimate_secondary()}}. See the documentation there for the expected +format.} + +\item{horizon}{Numeric, defaults to 7. Number of days into the future to +forecast.} + +\item{accumulate}{The number of days to accumulate when generating posterior +prediction, e.g. 7 for weekly accumulated forecasts.} + +\item{obs_column}{Character (default: "confirm"). If given, only the column +specified here will be used for checking missingness. This is useful if +using a data set that has multiple columns of hwich one of them +corresponds to observations that are to be processed here.} + +\item{by}{Character vector. Name(s) of any additional column(s) where +data processing should be done separately for each value in the column. +This is useful when using data representing e.g. multiple geographies. If +NULL (default) no such grouping is done.} +} +\value{ +A data.table with missing values for future dates +} +\description{ +Add missing values for future dates +} +\keyword{internal} diff --git a/man/apply_zero_threshold.Rd b/man/apply_zero_threshold.Rd new file mode 100644 index 000000000..4d123c9ce --- /dev/null +++ b/man/apply_zero_threshold.Rd @@ -0,0 +1,38 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/preprocessing.R +\name{apply_zero_threshold} +\alias{apply_zero_threshold} +\title{Convert zero case counts to \code{NA} (missing) if the 7-day average is above a +threshold.} +\usage{ +apply_zero_threshold(data, threshold = Inf, obs_column = "confirm") +} +\arguments{ +\item{data}{A \verb{} of confirmed cases (confirm) by date (date). +\code{confirm} must be numeric and \code{date} must be in date format. Optionally +this can also have a logical \code{accumulate} column which indicates whether +data should be added to the next data point. This is useful when modelling +e.g. weekly incidence data. See also the \code{\link[=fill_missing]{fill_missing()}} function which +helps add the \code{accumulate} column with the desired properties when dealing +with non-daily data. If any accumulation is done this happens after +truncation as specified by the \code{truncation} argument.} + +\item{threshold}{Numeric, defaults to \code{Inf}. Indicates if detected zero +cases are meaningful by using a threshold number of cases based on the +7-day average. If the average is above this threshold at the time of a +zero observation count then the zero is replaced with a missing (\code{NA}) +count and thus ignored in the likelihood.} + +\item{obs_column}{Character (default: "confirm"). If given, only the column +specified here will be used for checking missingness. This is useful if +using a data set that has multiple columns of hwich one of them +corresponds to observations that are to be processed here.} +} +\value{ +A data.table with the zero threshold applied. +} +\description{ +This function aims to detect spurious zeroes by comparing the 7-day average +of the case counts to a threshold. If the 7-day average is above the +threshold, the zero case count is replaced with \code{NA}. +} diff --git a/man/create_clean_reported_cases.Rd b/man/create_clean_reported_cases.Rd index 949880c81..d973aef40 100644 --- a/man/create_clean_reported_cases.Rd +++ b/man/create_clean_reported_cases.Rd @@ -34,11 +34,8 @@ to Inf. Indicates if detected zero cases are meaningful by using a threshold number of cases based on the 7-day average. If the average is above this threshold then the zero is replaced using \code{fill}.} -\item{fill}{Numeric, defaults to NA. Value to use to replace NA values or -zeroes that are flagged because the 7-day average is above the -\code{zero_threshold}. If the default NA is used then dates with NA values or with -7-day averages above the \code{zero_threshold} will be skipped in model fitting. -If this is set to 0 then the only effect is to replace NA values with 0.} +\item{fill}{Deprecated; zero dates with 7-day averages above the +\code{zero_threshold} will be skipped in model fitting.} \item{add_breakpoints}{Logical, defaults to TRUE. Should a breakpoint column be added to the data frame if it does not exist.} @@ -47,7 +44,7 @@ be added to the data frame if it does not exist.} A cleaned data frame of reported cases } \description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Filters leading zeros, completes dates, and applies an optional threshold at which point 0 cases are replaced with a user supplied value (defaults to \code{NA}). diff --git a/man/fill_missing.Rd b/man/fill_missing.Rd index 2120c6ddf..9e37e0b02 100644 --- a/man/fill_missing.Rd +++ b/man/fill_missing.Rd @@ -52,7 +52,7 @@ using a data set that has multiple columns of hwich one of them corresponds to observations that are to be processed here.} \item{by}{Character vector. Name(s) of any additional column(s) where -missing data should be processed separately for each value in the column. +data processing should be done separately for each value in the column. This is useful when using data representing e.g. multiple geographies. If NULL (default) no such grouping is done.} } diff --git a/man/filter_leading_zeros.Rd b/man/filter_leading_zeros.Rd new file mode 100644 index 000000000..527f21e6c --- /dev/null +++ b/man/filter_leading_zeros.Rd @@ -0,0 +1,41 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/preprocessing.R +\name{filter_leading_zeros} +\alias{filter_leading_zeros} +\title{Filter leading zeros from a data set.} +\usage{ +filter_leading_zeros(data, obs_column = "confirm", by = NULL) +} +\arguments{ +\item{data}{A \verb{} of confirmed cases (confirm) by date (date). +\code{confirm} must be numeric and \code{date} must be in date format. Optionally +this can also have a logical \code{accumulate} column which indicates whether +data should be added to the next data point. This is useful when modelling +e.g. weekly incidence data. See also the \code{\link[=fill_missing]{fill_missing()}} function which +helps add the \code{accumulate} column with the desired properties when dealing +with non-daily data. If any accumulation is done this happens after +truncation as specified by the \code{truncation} argument.} + +\item{obs_column}{Character (default: "confirm"). If given, only the column +specified here will be used for checking missingness. This is useful if +using a data set that has multiple columns of hwich one of them +corresponds to observations that are to be processed here.} + +\item{by}{Character vector. Name(s) of any additional column(s) where +data processing should be done separately for each value in the column. +This is useful when using data representing e.g. multiple geographies. If +NULL (default) no such grouping is done.} +} +\value{ +A data.table with leading zeros removed. +} +\description{ +Filter leading zeros from a data set. +} +\examples{ +cases <- data.frame( + date = as.Date("2020-01-01") + 0:10, + confirm = c(0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9) +) +filter_leading_zeros(cases) +} diff --git a/tests/testthat/test-create_clean_reported_cases.R b/tests/testthat/test-create_clean_reported_cases.R index 44bb0ef78..2314a2adc 100644 --- a/tests/testthat/test-create_clean_reported_cases.R +++ b/tests/testthat/test-create_clean_reported_cases.R @@ -1,8 +1,3 @@ - -test_that("create_clean_reported_cases runs without errors", { - expect_no_error(create_clean_reported_cases(example_confirmed, 7)) -}) - test_that("create_clean_reported_cases returns a data table", { result <- create_clean_reported_cases(example_confirmed, 7) expect_s3_class(result, "data.table") diff --git a/tests/testthat/test-estimate_infections.R b/tests/testthat/test-estimate_infections.R index 549cfeef0..598e5fca0 100644 --- a/tests/testthat/test-estimate_infections.R +++ b/tests/testthat/test-estimate_infections.R @@ -164,3 +164,12 @@ test_that("estimate_infections works as expected with failing chains", { ) )) }) + +test_that("a warning is thrown when using deprecated functionality", { + suppressWarnings(expect_deprecated(estimate_infections( + reported_cases, filter_leading_zeros = TRUE, verbose = FALSE + ), "filter_leading_zeros")) + suppressWarnings(expect_deprecated(estimate_infections( + reported_cases, zero_threshold = 50, verbose = FALSE + ), "zero_threshold")) +}) diff --git a/tests/testthat/test-estimate_secondary.R b/tests/testthat/test-estimate_secondary.R index 669679507..3d70b714c 100644 --- a/tests/testthat/test-estimate_secondary.R +++ b/tests/testthat/test-estimate_secondary.R @@ -224,6 +224,8 @@ test_that("estimate_secondary works with weigh_delay_priors = TRUE", { }) test_that("estimate_secondary works with filter_leading_zeros set", { + ## testing deprecated functionality + withr::local_options(lifecycle_verbosity = "quiet") modified_data <- inc_cases[1:10, secondary := 0] out <- estimate_secondary( modified_data, @@ -238,6 +240,8 @@ test_that("estimate_secondary works with filter_leading_zeros set", { }) test_that("estimate_secondary works with zero_threshold set", { + ## testing deprecated functionality + withr::local_options(lifecycle_verbosity = "quiet") modified_data <- inc_cases[sample(1:30, 10), primary := 0] out <- estimate_secondary( modified_data, @@ -249,3 +253,12 @@ test_that("estimate_secondary works with zero_threshold set", { expect_s3_class(out, "estimate_secondary") expect_named(out, c("predictions", "posterior", "data", "fit")) }) + +test_that("a warning is thrown when using deprecated functionality", { + suppressWarnings(expect_deprecated(estimate_secondary( + inc_cases, filter_leading_zeros = TRUE, verbose = FALSE + ), "filter_leading_zeros")) + suppressWarnings(expect_deprecated(estimate_secondary( + inc_cases, zero_threshold = 50, verbose = FALSE + ), "zero_threshold")) +})