diff --git a/NEWS.md b/NEWS.md index 7cbda965..e93ec839 100644 --- a/NEWS.md +++ b/NEWS.md @@ -24,3 +24,5 @@ * Specify number of samples draws with `iter_sampling` * Fix NOTE from missing variable name used with NSE * Read from new parameters schema +* Fix bugs in parameter reading from local test run +* Fix bugs in parameter reading from local test run diff --git a/R/fit_model.R b/R/fit_model.R index f81eafd7..aac36b5b 100644 --- a/R/fit_model.R +++ b/R/fit_model.R @@ -160,15 +160,24 @@ format_right_truncation <- function(pmf, data) { # silently removed if length of the PMF was longer than the data, # effectively eliminating the right-truncation correction - cli::cli_abort( + trunc_len <- nrow(data) + cli::cli_warn( c( + "Removing right-truncation PMF elements after {.val {trunc_len}}", "Right truncation PMF longer than the data", "PMF length: {.val {length(pmf)}}", "Data length: {.val {nrow(data)}}", - "PMF can only be up to length as the data" + "PMF can only be up to the length of the data" ), class = "right_trunc_too_long" ) + suppressWarnings({ + EpiNow2::trunc_opts( + dist = EpiNow2::dist_spec( + pmf = pmf[seq_len(trunc_len)] + ) + ) + }) } else { suppressWarnings({ EpiNow2::trunc_opts( diff --git a/R/parameters.R b/R/parameters.R index 9e90f083..b66394b3 100644 --- a/R/parameters.R +++ b/R/parameters.R @@ -131,7 +131,7 @@ read_interval_pmf <- function(path, rlang::arg_match(disease) as_of_date <- stringify_date(as_of_date) - cli::cli_alert_info("Reading {.arg right_truncation} from {.path {path}}") + cli::cli_alert_info("Reading {.arg {parameter}} from {.path {path}}") if (!file.exists(path)) { cli::cli_abort("File {.path {path}} does not exist", class = "file_not_found" diff --git a/tests/testthat/_snaps/fit_model.md b/tests/testthat/_snaps/fit_model.md new file mode 100644 index 00000000..a24cde65 --- /dev/null +++ b/tests/testthat/_snaps/fit_model.md @@ -0,0 +1,8 @@ +# Right truncation longer than data throws error + + Removing right-truncation PMF elements after 2 + Right truncation PMF longer than the data + PMF length: 3 + Data length: 2 + PMF can only be up to the length of the data + diff --git a/tests/testthat/test-fit_model.R b/tests/testthat/test-fit_model.R index ba768719..02305bcc 100644 --- a/tests/testthat/test-fit_model.R +++ b/tests/testthat/test-fit_model.R @@ -178,12 +178,11 @@ test_that("Right truncation longer than data throws error", { data <- data.frame(x = c(1, 2)) right_truncation_pmf <- c(0.1, 0.2, 0.7) - expect_error( + expect_snapshot_warning( format_right_truncation( right_truncation_pmf, data - ), - class = "right_trunc_too_long" + ) ) })