From d791ff860e7ea658cfa9b556bdacacfe7b37a66d Mon Sep 17 00:00:00 2001 From: Nat DeFries <42820733+nmdefries@users.noreply.github.com> Date: Thu, 29 Feb 2024 17:34:26 -0500 Subject: [PATCH 1/4] if as_of passed as date, check_is_recent should compare explicitly to a date --- R/utils.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index 5fbe5cbb..5f7ab3d3 100644 --- a/R/utils.R +++ b/R/utils.R @@ -22,7 +22,12 @@ format_list <- function(values) { #' #' @keywords internal check_is_recent <- function(dates, max_age) { - (!is.null(dates) && any(dates >= format(Sys.Date() - max_age, format = "%Y%m%d"))) + if (inherits(dates, "Date")) { + threshold <- Sys.Date() - max_age + } else { + threshold <- format(Sys.Date() - max_age, format = "%Y%m%d") + } + (!is.null(dates) && any(dates >= threshold)) } #' helper that checks whether a call is actually cachable From 9b97af449743778072eb56b6269b0a1d68927024 Mon Sep 17 00:00:00 2001 From: Nat DeFries <42820733+nmdefries@users.noreply.github.com> Date: Thu, 29 Feb 2024 17:43:51 -0500 Subject: [PATCH 2/4] test --- tests/testthat/test-utils.R | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index a95fbfe0..1ed8fbe6 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -65,6 +65,33 @@ test_that("check_is_cachable can handle both str and date inputs of various leng expect_no_error(check_is_cachable(epidata_call, fetch_args)) }) +test_that("check_is_recent can handle both str and date inputs of various lengths", { + # NULL + as_of <- NULL + expect_no_error(result <- check_is_recent(as_of, 10)) + expect_identical(result, FALSE) + + # as_of single string + as_of <- "2022-01-01" + expect_no_error(result <- check_is_recent(as_of, 10)) + expect_identical(result, FALSE) + + # as_of string vector + as_of <- c("2022-01-01", "3000-01-02", "3000-01-03") + expect_no_error(result <- check_is_recent(as_of, 10)) + expect_identical(result, TRUE) + + # as_of single date + as_of <- as.Date("2022-01-01") + expect_no_error(result <- check_is_recent(as_of, 10)) + expect_identical(result, FALSE) + + # as_of date vector + as_of <- as.Date(c("2022-01-01", "3000-01-02", "3000-01-03")) + expect_no_error(result <- check_is_recent(as_of, 10)) + expect_identical(result, TRUE) +}) + test_that("get_wildcard_equivalent_dates works in basic cases", { # Week date result <- get_wildcard_equivalent_dates(epirange(202002, 202013), "week") From c10b065152186f064870515bb1a5a0521ac977df Mon Sep 17 00:00:00 2001 From: Nat DeFries <42820733+nmdefries@users.noreply.github.com> Date: Thu, 29 Feb 2024 18:00:19 -0500 Subject: [PATCH 3/4] version and news --- DESCRIPTION | 2 +- NEWS.md | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 89fe1ad4..b478a352 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: epidatr Type: Package Title: Client for Delphi's 'Epidata' API -Version: 1.1.0 +Version: 1.1.1 Authors@R: c( person("Logan", "Brooks", email = "lcbrooks@andrew.cmu.edu", role = c("aut")), diff --git a/NEWS.md b/NEWS.md index 10626ad3..432de12f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,13 @@ +# epidatr 1.2.0 + +## Changes + +## Features + +## Patches +- Fixed failure when passing `as_of` values in `Date` format to + `pub_covidcast` while caching is enabled (#259) + # epidatr 1.1.0 ## Changes From 739eebd7836bd653fa5331b88ec318119b74739e Mon Sep 17 00:00:00 2001 From: nmdefries <42820733+nmdefries@users.noreply.github.com> Date: Thu, 29 Feb 2024 18:07:07 -0500 Subject: [PATCH 4/4] Lower news version number Co-authored-by: David Weber --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 432de12f..25512ee5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# epidatr 1.2.0 +# epidatr 1.1.1 ## Changes