eiadate {eia} | R Documentation |
EIA date parsing
Description
Helper functions for manipulating and converting between regular year-month-day date strings and EIA date string notation.
Usage
eiadate_to_date(x)
date_to_eiadate(x, date_format = c("A", "Q", "M", "W", "D", "H"))
eiadate_to_date_seq(start, end, weekly = FALSE)
Arguments
x |
character, EIA date string; character or date object for regular dates. See details. |
date_format |
EIA date format: "A", "Q", "M", "W", "D", "H". These stand for annual, quarterly, monthly, weekly, daily, hourly. See details. |
start |
start EIA date or date. |
end |
end EIA date or date. |
weekly |
logical. See details. |
Details
There is no reason to mix EIA date formats in this context. Functions that
take EIA date strings expect a consistent format. Also, EIA date formats are
parsed automatically from the dates themselves. However, daily and weekly use
the same format. Too avoid ambiguity in eia_date_seq()
, daily is assumed;
set weekly = TRUE
to treat as weekly.
When providing a real date or date string, such as to date_to_eiadate()
,
dates should be in YYYY-MM-DD
format, or at least any format that can be
parsed by lubridate::ymd
or lubridate::ymd_hms
for dates and hourly date
times, respectively.
"LH"
is not a supported date format. Use "H"
. The API does not translate
the date and time when using "LH"
anyhow; it simply appends the date string
with the number of hours time difference.
Examples
eiadate_to_date(c("2018-03", "2018-04"))
date_to_eiadate("2018-05-14", "A")
date_to_eiadate("2018-05-14", "Q")
date_to_eiadate("2018-05-14", "M")
(x <- eiadate_to_date_seq("2018-Q1", "2018-Q4"))
date_to_eiadate(x, "Q")
date_to_eiadate(x, "M")
(x <- eiadate_to_date("2019-01-02T16Z"))
date_to_eiadate(x, "H")
(x <- eiadate_to_date_seq("2019-01-02T16Z", "2019-01-02T19Z"))
date_to_eiadate(x, "H")