Skip to content

Commit

Permalink
warn about week conversion; handle single week date
Browse files Browse the repository at this point in the history
  • Loading branch information
nmdefries committed Jan 5, 2024
1 parent 7c6d207 commit 357b39d
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion R/endpoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub_covid_hosp_facility_lookup <- function(
#' @param fetch_args [`fetch_args`]. Additional arguments to pass to `fetch()`.
#' @return [`tibble::tibble`]
#'
#' @importFrom checkmate test_class
#' @importFrom checkmate test_class test_integerish test_character
#'
#' @seealso [`pub_covid_hosp_facility()`], [`epirange()`]
#' @keywords endpoint
Expand All @@ -201,7 +201,28 @@ pub_covid_hosp_facility <- function(
# but correspond to epiweeks. Allow `collection_weeks` to be provided in
# either day or week format.
if (test_class(collection_weeks, "EpiRange")) {
cli::cli_warn(
c(
"`collection_weeks` {collection_weeks} is in week format but
`pub_covid_hosp_facility` expects day format; dates will be automatically
converted to day format"
),
class = "epidatr__epirange_week_coercion"
)
collection_weeks <- convert_epirange_format(collection_weeks, to_type = "day")
# Single week date.
} else if (
(test_integerish(collection_weeks) || test_character(collection_weeks)) &&
nchar(collection_weeks) == 6) {
cli::cli_warn(
c(
"`collection_weeks` {collection_weeks} is in week format but
`pub_covid_hosp_facility` expects day format; dates will be automatically
converted to day format"
),
class = "epidatr__single_week_coercion"
)
collection_weeks <- parse_api_week(collection_weeks)
}

create_epidata_call(
Expand Down

0 comments on commit 357b39d

Please sign in to comment.