Skip to contents

Finds the last day of the collection period whose samples have largely come back from the laboratory. A collection month fails when fewer than resolved_min of its samples are resolved. The period ends the day before the earliest failing month that is no older than settle_months before the month of as_of. A month older than that is taken as final even if it never reached resolved_min, so it no longer holds the period back. When no month fails, the period ends on the last day of the latest sampled month. The result is never later than as_of.

Usage

es_complete_end(
  resolution,
  as_of = Sys.Date(),
  resolved_min = 0.8,
  settle_months = 3L
)

Arguments

resolution

A monthly summary with columns month (the first day of each collection month) and resolved_share (between 0 and 1), as returned by calc_es_resolution().

as_of

The reporting date, as a Date or a string that as.Date() reads. Defaults to Sys.Date(). The result is never later than it.

resolved_min

Share of a month's samples that must be resolved for the month to count as complete. Default 0.80.

settle_months

Number of months after which a month still below resolved_min is taken as final. Default 3.

Value

A single Date, or NA when resolution has no rows.

Examples

res <- tibble::tibble(
  month = as.Date(c("2024-01-01", "2024-02-01", "2024-03-01")),
  resolved_share = c(1, 0.9, 0.4)
)
es_complete_end(res, as_of = as.Date("2024-04-15"))
#> [1] "2024-02-29"