diff --git a/DESCRIPTION b/DESCRIPTION index 12d86602b..50bb77ec2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: epipredict Title: Basic epidemiology forecasting methods -Version: 0.0.15 +Version: 0.0.16 Authors@R: c( person("Daniel", "McDonald", , "daniel@stat.ubc.ca", role = c("aut", "cre")), person("Ryan", "Tibshirani", , "ryantibs@cmu.edu", role = "aut"), diff --git a/NEWS.md b/NEWS.md index c756cb34d..bf3f4d9d5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -43,6 +43,7 @@ Pre-1.0.0 numbering scheme: 0.x will indicate releases, while 0.0.x will indicat - `arx_fcast_epi_workflow()` and `arx_class_epi_workflow()` now default to `trainer = parsnip::logistic_reg()` to match their more canned versions. - add a `forecast()` method simplify generating forecasts -- refactor `bake.epi_recipe()` and remove `epi_juice()`. -- Revise `compat-purrr` to use the r-lang `standalone-*` version (via +- refactor `bake.epi_recipe()` and remove `epi_juice()`. +- Revise `compat-purrr` to use the r-lang `standalone-*` version (via `{usethis}`) +- `epi_recipe()` will now warn when given non-`epi_df` data diff --git a/R/epi_recipe.R b/R/epi_recipe.R index e5182b99b..b40d7e510 100644 --- a/R/epi_recipe.R +++ b/R/epi_recipe.R @@ -20,6 +20,10 @@ epi_recipe.default <- function(x, ...) { if (is.matrix(x) || is.data.frame(x) || tibble::is_tibble(x)) { x <- x[1, , drop = FALSE] } + cli_warn( + "epi_recipe has been called with a non-epi_df object, returning a regular recipe. Various + step_epi_* functions will not work." + ) recipes::recipe(x, ...) } @@ -147,6 +151,10 @@ epi_recipe.formula <- function(formula, data, ...) { data <- data[1, ] # check for minus: if (!epiprocess::is_epi_df(data)) { + cli_warn( + "epi_recipe has been called with a non-epi_df object, returning a regular recipe. Various + step_epi_* functions will not work." + ) return(recipes::recipe(formula, data, ...)) } @@ -333,15 +341,11 @@ update_epi_recipe <- function(x, recipe, ..., blueprint = default_epi_recipe_blu #' illustrations of the different types of updates. #' #' @param x A `epi_workflow` or `epi_recipe` object -#' #' @param which_step the number or name of the step to adjust -#' #' @param ... Used to input a parameter adjustment -#' #' @param blueprint A hardhat blueprint used for fine tuning the preprocessing. #' -#' @return -#' `x`, updated with the adjustment to the specified `epi_recipe` step. +#' @return `x`, updated with the adjustment to the specified `epi_recipe` step. #' #' @export #' @examples @@ -383,8 +387,7 @@ adjust_epi_recipe <- function(x, which_step, ..., blueprint = default_epi_recipe #' @rdname adjust_epi_recipe #' @export -adjust_epi_recipe.epi_workflow <- function( - x, which_step, ..., blueprint = default_epi_recipe_blueprint()) { +adjust_epi_recipe.epi_workflow <- function(x, which_step, ..., blueprint = default_epi_recipe_blueprint()) { recipe <- adjust_epi_recipe(workflows::extract_preprocessor(x), which_step, ...) update_epi_recipe(x, recipe, blueprint = blueprint) @@ -392,8 +395,7 @@ adjust_epi_recipe.epi_workflow <- function( #' @rdname adjust_epi_recipe #' @export -adjust_epi_recipe.epi_recipe <- function( - x, which_step, ..., blueprint = default_epi_recipe_blueprint()) { +adjust_epi_recipe.epi_recipe <- function(x, which_step, ..., blueprint = default_epi_recipe_blueprint()) { if (!(is.numeric(which_step) || is.character(which_step))) { cli::cli_abort( c("`which_step` must be a number or a character.", diff --git a/tests/testthat/test-epi_recipe.R b/tests/testthat/test-epi_recipe.R index d288ec058..75726652d 100644 --- a/tests/testthat/test-epi_recipe.R +++ b/tests/testthat/test-epi_recipe.R @@ -4,20 +4,23 @@ test_that("epi_recipe produces default recipe", { x = 1:5, y = 1:5, time_value = seq(as.Date("2020-01-01"), by = 1, length.out = 5) ) - rec <- recipes::recipe(tib) - rec$template <- rec$template[1, ] - expect_identical(rec, epi_recipe(tib)) + expected_rec <- recipes::recipe(tib) + expected_rec$template <- expected_rec$template[1, ] + expect_warning(rec <- epi_recipe(tib), regexp = "epi_recipe has been called with a non-epi_df object") + expect_identical(expected_rec, rec) expect_equal(nrow(rec$template), 1L) - rec <- recipes::recipe(y ~ x, tib) - rec$template <- rec$template[1, ] - expect_identical(rec, epi_recipe(y ~ x, tib)) + expected_rec <- recipes::recipe(y ~ x, tib) + expected_rec$template <- expected_rec$template[1, ] + expect_warning(rec <- epi_recipe(y ~ x, tib), regexp = "epi_recipe has been called with a non-epi_df object") + expect_identical(expected_rec, rec) expect_equal(nrow(rec$template), 1L) m <- as.matrix(tib) - rec <- recipes::recipe(m) - rec$template <- rec$template[1, ] - expect_identical(rec, epi_recipe(m)) + expected_rec <- recipes::recipe(m) + expected_rec$template <- expected_rec$template[1, ] + expect_warning(rec <- epi_recipe(m), regexp = "epi_recipe has been called with a non-epi_df object") + expect_identical(expected_rec, rec) expect_equal(nrow(rec$template), 1L) })