Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return epinow()'s "timing" output as <difftime> #688

Merged
merged 9 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# EpiNow2 (development version)

## Model changes

- `epinow()` now returns the "timing" output in a "time difference"" format that is easier to understand and work with. By @jamesmbaazam in #688 and reviewed by @.
jamesmbaazam marked this conversation as resolved.
Show resolved Hide resolved

# EpiNow2 1.5.2

A patch release to further fix an issue with the date in the package citation. This has now been addressed by removing `inst/CITATION`.
Expand Down
2 changes: 1 addition & 1 deletion R/epinow.R
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ epinow <- function(data,

# log timing if specified
if (output["timing"]) {
out$timing <- round(as.numeric(end_time - start_time), 1)
out$timing <- difftime(end_time, start_time)
if (!is.null(target_folder)) {
saveRDS(out$timing, file.path(target_folder, "runtime.rds"))
}
Expand Down
3 changes: 2 additions & 1 deletion R/summarise.R
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,8 @@ regional_runtimes <- function(regional_output = NULL,
if (!is.null(regional_output)) {
timings <- data.table::data.table(
region = names(regional_output),
time = unlist(purrr::map(regional_output, ~ .$timing))
# purrr::map_vec will preserve the difftime class
time = unlist(purrr::map_vec(regional_output, ~ .$timing))
jamesmbaazam marked this conversation as resolved.
Show resolved Hide resolved
)
} else {
if (is.null(target_date)) {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-regional_epinow.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test_that("regional_epinow produces expected output when run with default settin
"summarised_measures", "reported_cases", "high_plots", "plots"
))
expect_equal(names(out$regional$realland), c("estimates", "estimated_reported_cases", "summary", "plots", "timing"))
expect_type(out$regional$realland$timing, "double")
expect_s3_class(out$regional$realland$timing, "difftime")
df_non_zero(out$regional$realland$estimates$samples)
df_non_zero(out$regional$realland$estimates$summarised)
df_non_zero(out$regional$realland$estimated_reported_cases$samples)
Expand Down Expand Up @@ -101,7 +101,7 @@ test_that("regional_epinow produces expected output when run with region specifi
"summarised_measures", "reported_cases", "high_plots", "plots"
))
expect_equal(names(out$regional$realland), c("estimates", "estimated_reported_cases", "summary", "plots", "timing"))
expect_type(out$regional$realland$timing, "double")
expect_s3_class(out$regional$realland$timing, "difftime")
df_non_zero(out$regional$realland$estimates$samples)
df_non_zero(out$regional$realland$estimates$summarised)
df_non_zero(out$regional$realland$estimated_reported_cases$samples)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-regional_runtimes.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ test_that("regional_runtimes produces expected output when with input", {
runtimes <- regional_runtimes(out$regional)
expect_equal(names(runtimes), c("region", "time"))
df_non_zero(runtimes)
expect_type(runtimes$time, "double")
expect_s3_class(runtimes$time, "difftime")
})
Loading