From 859a9a154723a48e5b698bb816a548c28dd18331 Mon Sep 17 00:00:00 2001 From: Greg Faletto Date: Tue, 5 May 2026 09:39:46 -0700 Subject: [PATCH] fix: display latency adjustment info on canned forecasters (#447) print.canned_epipred() was supposed to surface latency-adjustment information for canned forecasters whose recipe contains a step_adjust_latency. The gating conditional checked for a top-level "pre" field on the canned forecaster, but canned forecasters' top-level fields are predictions, epi_workflow, and metadata. The check always evaluated FALSE, leaving the latency-info block as dead code. Replace the predicate with !is.null(x$epi_workflow$pre$actions$recipe), which correctly tests for a recipe preprocessor on the embedded workflow. The existing snapshot tests for arx_forecaster with extend_lags and extend_ahead regenerate to include the previously-missing "Lags adjusted" / "Aheads adjusted" lines. Two supplementary expect_match assertions are added as defensive guards. Also adds .workflow/, .plans/, .claude/ to both .gitignore and .Rbuildignore for personal agent-tooling directories. Co-Authored-By: Claude Opus 4.7 (1M context) --- .Rbuildignore | 3 +++ .gitignore | 3 +++ DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/canned-epipred.R | 2 +- tests/testthat/_snaps/snapshots.md | 2 ++ tests/testthat/test-snapshots.R | 8 ++++++++ 7 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index dc41e6223..92351a76a 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -22,3 +22,6 @@ ^.lintr$ ^.venv$ ^inst/templates$ +^\.workflow$ +^\.plans$ +^\.claude$ diff --git a/.gitignore b/.gitignore index ae7df4125..51bb061ea 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,6 @@ inst/doc renv.lock renv/ .Renviron +.workflow/ +.plans/ +.claude/ diff --git a/DESCRIPTION b/DESCRIPTION index 34ed7bb8e..ec393c6eb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: epipredict Title: Basic epidemiology forecasting methods -Version: 0.2.2 +Version: 0.2.3 Authors@R: c( person("Daniel J.", "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 70331d732..973f7cd14 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,10 @@ Pre-1.0.0 numbering scheme: 0.x will indicate releases, while 0.0.x will indicate PR's. +# epipredict 0.2.3 + +- Fix `print.canned_epipred()` so the latency-adjustment information actually displays for canned forecasters that include `step_adjust_latency` in their recipe (#447). + # epipredict 0.2.2 - Fix `autoplot.epi_workflow()` to correctly handle the response variable and avoid errors related to `.response`. diff --git a/R/canned-epipred.R b/R/canned-epipred.R index 7d53862c2..2683acad6 100644 --- a/R/canned-epipred.R +++ b/R/canned-epipred.R @@ -112,7 +112,7 @@ print.canned_epipred <- function(x, name, ...) { "At forecast date{?s}: {.val {fds}},", "For target date{?s}: {.val {tds}}," )) - if ("pre" %in% names(x) && "actions" %in% names(x$pre) && "recipe" %in% names(x$pre$actions)) { + if (!is.null(x$epi_workflow$pre$actions$recipe)) { fit_recipe <- extract_recipe(x$epi_workflow) if (detect_step(fit_recipe, "adjust_latency")) { is_adj_latency <- map_lgl(fit_recipe$steps, function(x) inherits(x, "step_adjust_latency")) diff --git a/tests/testthat/_snaps/snapshots.md b/tests/testthat/_snaps/snapshots.md index 515930195..6be009c4a 100644 --- a/tests/testthat/_snaps/snapshots.md +++ b/tests/testthat/_snaps/snapshots.md @@ -727,6 +727,7 @@ * 56 unique geographic regions, * At forecast date: 2022-01-03, * For target date: 2022-01-10, + * Lags adjusted per column: case_rate=3, death_rate=3 --- @@ -750,6 +751,7 @@ * 56 unique geographic regions, * At forecast date: 2022-01-03, * For target date: 2022-01-10, + * Aheads adjusted for death_rate=3 # arx_classifier snapshots diff --git a/tests/testthat/test-snapshots.R b/tests/testthat/test-snapshots.R index eb0439c10..e559ff481 100644 --- a/tests/testthat/test-snapshots.R +++ b/tests/testthat/test-snapshots.R @@ -132,6 +132,10 @@ test_that("arx_forecaster output format snapshots", { expect_equal(as.Date(format(out2$metadata$forecast_created, "%Y-%m-%d")), Sys.Date()) out2$metadata$forecast_created <- as.Date("1999-01-01") expect_snapshot(out2) + expect_match( + paste(testthat::capture_messages(print(out2)), collapse = ""), + "adjusted" + ) out3 <- arx_forecaster(jhu, "death_rate", c("case_rate", "death_rate"), trainer = quantile_reg(), @@ -143,6 +147,10 @@ test_that("arx_forecaster output format snapshots", { expect_equal(as.Date(format(out3$metadata$forecast_created, "%Y-%m-%d")), Sys.Date()) out3$metadata$forecast_created <- as.Date("1999-01-01") expect_snapshot(out3) + expect_match( + paste(testthat::capture_messages(print(out3)), collapse = ""), + "adjusted" + ) }) test_that("arx_classifier snapshots", {