Skip to content

Commit

Permalink
Helper fns support start dates
Browse files Browse the repository at this point in the history
  • Loading branch information
pratikunterwegs committed Mar 22, 2024
1 parent 2d28d71 commit 386273e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ new_infections <- function(data,
)
checkmate::assert_names(
colnames(data),
must.include = c("time", "demography_group", "compartment", "value")
must.include = c("time", "date", "demography_group", "compartment", "value")
)
checkmate::assert_character(
compartments_from_susceptible,
Expand All @@ -256,7 +256,7 @@ new_infections <- function(data,
# cast data wide, this makes a copy
data <- data.table::dcast(
data,
time + demography_group ~ compartment,
time + date + demography_group ~ compartment,
value.var = "value"
)

Expand All @@ -281,9 +281,11 @@ new_infections <- function(data,
# return data in long format, by demographic group by default,
# or aggregated otherwise; do not return other compartments
# subsetting below creates a copy - input `data` is safe
data <- data[, c("time", "demography_group", "new_infections")]
data <- data[, c("time", "date", "demography_group", "new_infections")]
if (!by_group) {
data <- data[, list(new_infections = sum(new_infections)), by = "time"]
data <- data[, list(
new_infections = sum(new_infections)
), by = c("time", "date")]
}

# return data
Expand Down
2 changes: 1 addition & 1 deletion R/tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# basic input checking only
stopifnot(
"`x` must be a list with vector elements" =
is.list(x) && all(vapply(x, is.vector, TRUE))
checkmate::test_list(x, types = c("numeric", "Date"))
)
lens <- lengths(x)
not_scalar <- lens != 1L
Expand Down

0 comments on commit 386273e

Please sign in to comment.