Skip to content

Commit

Permalink
cleanup from attempted run (#55)
Browse files Browse the repository at this point in the history
* Read param as a var in CLI message

* Truncate PMFs longer than the data

To the length of the data and throw a warning rather than an error.
This change allows us to run on old right-truncation estimates.

* Bump NEWS

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Call a length a length

* No margin for error

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
zsusswein and pre-commit-ci[bot] authored Oct 15, 2024
1 parent dd0c2ce commit 0fe4b3e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 11 additions & 2 deletions R/fit_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion R/parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/fit_model.md
Original file line number Diff line number Diff line change
@@ -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

5 changes: 2 additions & 3 deletions tests/testthat/test-fit_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
)
})

Expand Down

0 comments on commit 0fe4b3e

Please sign in to comment.