Skip to content

Commit dc3e6ec

Browse files
committed
add as_of arg to hosp state timeseries
1 parent 83e986b commit dc3e6ec

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

R/endpoints.R

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,28 +455,53 @@ pub_covid_hosp_facility <- function(
455455
#'
456456
#' @param states character. Two letter state abbreviations.
457457
#' @param dates [`timeset`]. Dates to fetch.
458-
#' @param issues [`timeset`]. Optionally, the issues to fetch. If not set, the
459-
#' most recent issue is returned.
460458
#' @param ... not used for values, forces later arguments to bind by name
459+
#' @param as_of Date. Optionally, the as of date for the issues to fetch. If not
460+
#' specified, the most recent data is returned. Mutually exclusive with
461+
#' `issues` or `lag`.
462+
#' @param issues [`timeset`]. Optionally, the issue of the data to fetch. If not
463+
#' specified, the most recent issue is returned. Mutually exclusive with
464+
#' `as_of` or `lag`.
461465
#' @param fetch_args [`fetch_args`]. Additional arguments to pass to `fetch()`.
462466
#' @return [`tibble::tibble`]
463467
#'
464468
#' @keywords endpoint
465469
#' @export
466470
#
467-
pub_covid_hosp_state_timeseries <- function(states, dates, ..., issues = NULL, fetch_args = fetch_args_list()) {
471+
pub_covid_hosp_state_timeseries <- function(
472+
states,
473+
dates,
474+
...,
475+
as_of = NULL,
476+
issues = NULL,
477+
fetch_args = fetch_args_list()) {
478+
# Check parameters
479+
if (missing(states) || missing(dates)) {
480+
stop(
481+
"`states` and `dates` are both required"
482+
)
483+
}
484+
485+
if (sum(!is.null(issues), !is.null(as_of)) > 1) {
486+
stop("`issues`and `as_of` are mutually exclusive")
487+
}
488+
468489
assert_character_param("states", states)
469490
assert_timeset_param("dates", dates)
491+
assert_date_param("as_of", as_of, len = 1, required = FALSE)
470492
assert_timeset_param("issues", issues, required = FALSE)
493+
471494
dates <- parse_timeset_input(dates)
472495
issues <- parse_timeset_input(issues)
496+
as_of <- parse_timeset_input(as_of)
473497

474498
create_epidata_call(
475499
"covid_hosp_state_timeseries/",
476500
list(
477501
states = states,
478502
dates = dates,
479-
issues = issues
503+
issues = issues,
504+
as_of = as_of
480505
),
481506
list(
482507
create_epidata_field_info("state", "text"),

man/pub_covid_hosp_state_timeseries.Rd

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)