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()
.
Value
An IDate vector.
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
coerce_dt()
,
convert_cmdstan_to_rstan()
,
expose_stan_fns()
,
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)
}
)
#> <simpleError in coerce_date(c("2020-05-28", "2020-o5-29")): Failed to parse with `as.IDate`: {2020-o5-29} (indices {2}).>