Provides consistent coercion of inputs to IDate with error handling
Arguments
- dates
A vector-like input, which the function attempts to coerce via
data.table::as.IDate()
. Defaults to NULL.
Details
If any of the elements of dates
cannot be coerced,
this function will result in an error, indicating all indices
which cannot be coerced to IDate.
Internal methods of epinowcast assume dates are represented as IDate.
See also
Utility functions
aggregate_rolling_sum()
,
coerce_dt()
,
date_to_numeric_modulus()
,
get_internal_timestep()
,
is.Date()
,
stan_fns_as_string()
Examples
# works
coerce_date(c("2020-05-28", "2020-05-29"))
#> [1] "2020-05-28" "2020-05-29"
# does not, indicates index 2 is problem
tryCatch(
coerce_date(c("2020-05-28", "2020-o5-29")),
error = function(e) {
print(e)
}
)
#> <error/rlang_error>
#> Error in `coerce_date()`:
#> ! Failed to parse with `as.IDate`: 2020-o5-29 (indices 2).
#> ---
#> Backtrace:
#> ▆
#> 1. └─pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
#> 2. └─pkgdown::build_site(...)
#> 3. └─pkgdown:::build_site_local(...)
#> 4. └─pkgdown::build_reference(...)
#> 5. └─purrr::map(...)
#> 6. └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
#> 7. ├─purrr:::with_indexed_errors(...)
#> 8. │ └─base::withCallingHandlers(...)
#> 9. ├─purrr:::call_with_cleanup(...)
#> 10. └─pkgdown (local) .f(.x[[i]], ...)
#> 11. ├─base::withCallingHandlers(...)
#> 12. └─pkgdown:::data_reference_topic(...)
#> 13. └─pkgdown:::run_examples(...)
#> 14. └─pkgdown:::highlight_examples(code, topic, env = env)
#> 15. └─downlit::evaluate_and_highlight(...)
#> 16. └─evaluate::evaluate(code, child_env(env), new_device = TRUE, output_handler = output_handler)
#> 17. └─evaluate:::evaluate_call(...)
#> 18. ├─evaluate (local) timing_fn(...)
#> 19. ├─evaluate (local) handle(...)
#> 20. │ └─base::try(f, silent = TRUE)
#> 21. │ └─base::tryCatch(...)
#> 22. │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 23. │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 24. │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 25. ├─base::withCallingHandlers(...)
#> 26. ├─base::withVisible(...)
#> 27. └─evaluate:::eval_with_user_handlers(expr, envir, enclos, user_handlers)
#> 28. └─base::eval(expr, envir, enclos)
#> 29. └─base::eval(expr, envir, enclos)
#> 30. ├─base::tryCatch(...)
#> 31. │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 32. │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 33. │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 34. └─epinowcast::coerce_date(c("2020-05-28", "2020-o5-29"))