From 4f4c14c31b4d258a5c754053151b2e1cb338edfb Mon Sep 17 00:00:00 2001 From: Nat DeFries <42820733+nmdefries@users.noreply.github.com> Date: Thu, 29 Feb 2024 18:26:50 -0500 Subject: [PATCH 1/4] change expected timecol output type based on `time_type` --- R/endpoints.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/endpoints.R b/R/endpoints.R index 0146ca64..6949a136 100644 --- a/R/endpoints.R +++ b/R/endpoints.R @@ -1051,8 +1051,8 @@ 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"), From 0424f6b2828ae500f51fe02aa37280f469c13038 Mon Sep 17 00:00:00 2001 From: nmdefries Date: Thu, 29 Feb 2024 23:29:34 +0000 Subject: [PATCH 2/4] style: styler (GHA) --- R/endpoints.R | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/R/endpoints.R b/R/endpoints.R index 6949a136..d1e30ca5 100644 --- a/R/endpoints.R +++ b/R/endpoints.R @@ -1051,8 +1051,14 @@ pub_covidcast <- function( c("day", "week") ), create_epidata_field_info("geo_value", "text"), - 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("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"), From 0209e95f1624325531f0694594d2d487db785f97 Mon Sep 17 00:00:00 2001 From: Nat DeFries <42820733+nmdefries@users.noreply.github.com> Date: Fri, 1 Mar 2024 12:06:21 -0500 Subject: [PATCH 3/4] error if nchs requested not weekly --- R/endpoints.R | 7 +++++++ tests/testthat/test-endpoints.R | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/R/endpoints.R b/R/endpoints.R index d1e30ca5..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( 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") +}) From 327d7fcdc30ac1275346e59246b9668212b255f0 Mon Sep 17 00:00:00 2001 From: Nat DeFries <42820733+nmdefries@users.noreply.github.com> Date: Fri, 1 Mar 2024 12:43:28 -0500 Subject: [PATCH 4/4] version and news --- DESCRIPTION | 2 +- NEWS.md | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) 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