Skip to contents

assert that a date corresponds to a given epidemiological week and year, according to the given epiweek standard.

Usage

assert_date_in_epiweek(
  date,
  expected_epiweek,
  expected_epiyear,
  epiweek_standard
)

Arguments

date

Vector of dates to validate.

expected_epiweek

Vector of expected epiweek values.

expected_epiyear

Vector of expected epiyear values.

epiweek_standard

One of "MMWR" or "USA" (USA MMWR epiweek, starts on Sunday) and "ISO" (ISO week, starts on Monday). Not case-sensitive. Must be a single value.

Value

Nothing on success, or raise an error if the assertion fails.

Examples

assert_date_in_epiweek("2025-01-02", 1, 2025, "USA")
assert_date_in_epiweek(
  c("2024-12-27", "2025-01-05"),
  c(52, 1),
  c(2024, 2025),
  "ISO"
)

tryCatch(
  assert_date_in_epiweek(
    "2024-12-01", 52, 2024, "ISO"
  ),
  error = \(e) print(e)
)
#> <error/rlang_error>
#> Error in `assert_date_in_epiweek()`:
#> ! Date(s) '2024-12-01' failed epiweek validation! Did not obtain the
#>   user-requested values for `expected_epiweek` and `expected_epiyear` when
#>   passed to the epiweek and epiyear functions corresponding to epiweek standard
#>   'ISO'
#> ---
#> Backtrace:
#>     
#>  1. ├─base::tryCatch(...)
#>  2. └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#>  3. └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>  4. └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#>  5. └─forecasttools::assert_date_in_epiweek("2024-12-01", 52, 2024, "ISO")