diff --git a/DESCRIPTION b/DESCRIPTION index b478a352..bb6a971b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: epidatr Type: Package Title: Client for Delphi's 'Epidata' API -Version: 1.1.1 +Version: 1.1.2 Authors@R: c( person("Logan", "Brooks", email = "lcbrooks@andrew.cmu.edu", role = c("aut")), diff --git a/NEWS.md b/NEWS.md index 25512ee5..f0412963 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,8 +5,10 @@ ## Features ## Patches -- Fixed failure when passing `as_of` values in `Date` format to - `pub_covidcast` while caching is enabled (#259) +- Fix failure when passing `as_of` values in `Date` format to + `pub_covidcast` while caching is enabled (#259). +- For `pub_covidcast` data source `nchs-mortality`, parse dates as `epiweek` + and expect `epiweek` inputs from user (#260). # epidatr 1.1.0 diff --git a/R/endpoints.R b/R/endpoints.R index 0146ca64..f58c0822 100644 --- a/R/endpoints.R +++ b/R/endpoints.R @@ -1025,6 +1025,13 @@ pub_covidcast <- function( as_of <- parse_timeset_input(as_of) issues <- parse_timeset_input(issues) + if (source == "nchs-mortality" && time_type != "week") { + cli::cli_abort( + "{source} data is only available at the week level", + class = "epidatr__nchs_week_only" + ) + } + create_epidata_call( "covidcast/", list( @@ -1051,8 +1058,14 @@ pub_covidcast <- function( c("day", "week") ), create_epidata_field_info("geo_value", "text"), - create_epidata_field_info("time_value", "date"), - create_epidata_field_info("issue", "date"), + create_epidata_field_info("time_value", switch(time_type, + day = "date", + week = "epiweek" + )), + create_epidata_field_info("issue", switch(time_type, + day = "date", + week = "epiweek" + )), create_epidata_field_info("lag", "int"), create_epidata_field_info("value", "float"), create_epidata_field_info("stderr", "float"), diff --git a/tests/testthat/test-endpoints.R b/tests/testthat/test-endpoints.R index 39194535..731657e3 100644 --- a/tests/testthat/test-endpoints.R +++ b/tests/testthat/test-endpoints.R @@ -517,3 +517,14 @@ test_that("pub_covid_hosp_state_timeseries supports versioned queries", { expect_identical(epidata_call$params$as_of, 20220101) expect_identical(epidata_call$params$lag, NULL) }) + +test_that("nchs-mortality call fails if time_type not week", { + expect_error(pub_covidcast( + source = "nchs-mortality", + signals = "signal", + time_type = "day", + geo_type = "state", + time_values = "*", + geo_values = "*" + ), class = "epidatr__nchs_week_only") +})