We need to map "dates" onto dust::dust's concept of model
"step" and we do this by mapping a date such as 2020-03-02 into
the number of days into 2020 (62 here, with the 1st of January
being day 1). We call this integer number a "sircovid date".
sircovid_date(date) sircovid_date_as_date(date) as_sircovid_date(date) as_date(date)
| date | A Date object, or something that can be converted to one, or a "sircovid date"; see Details |
|---|
An integer, being the number of days into 2020
There are several related functions here
sircovid_date converts its argument into an R Date object,
then applies this tranformation. If the argument is not a Date
object or a string representing one, an error will be thrown.
sircovid_date_to_date does the reverse conversion to
sircovid_date, converting an integer sircovid date into an R
Date
as_sircovid_date does the same conversion as sircovid_date
but will assume that an integer already represents a sircovid
date and will return it unmodified rather than erroring.
as_date does a string to date conversion, using as.Date()
but requiring the dates are in ISO 8601 (YYYY-MM-DD) format (it
is a helper that avoids conversion to NA, instead throwing an
error)
# Convert dates into sircovid dates: sircovid2::sircovid_date("2020-01-01")#> [1] 1#> [1] 61 275# Reverse the conversion: sircovid2::sircovid_date_as_date(1)#> [1] "2020-01-01"#> [1] "2020-03-01" "2020-10-01"#> Error in as_date(date) : Expected ISO dates or R dates - please convert# ...but allowed with as_sircovid_date sircovid2::as_sircovid_date(61)#> [1] 61# Strict date conversion with as_date sircovid2::as_date("2020-03-01")#> [1] "2020-03-01"#> Error in sircovid2::as_date("03-01-2020") : #> Expected ISO dates or R dates - please convert