Skip to content

covidcast's as_of should not "require" an epirange, and does not properly handle epiranges #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
brookslogan opened this issue Sep 27, 2022 · 0 comments · Fixed by #89
Assignees
Labels
bug Something isn't working P1 medium priority

Comments

@brookslogan
Copy link
Contributor

brookslogan commented Sep 27, 2022

See line here. as_of in the covidcast package allows only a single date; we should support that in epidatr [it looks like we already support this in epidatr, but we should make sure to test we can use a Date class here after #47 is fixed, and/or clarify the error message that an "epirange" is required]. Further, epiranges aren't actually handled properly here; providing a non-zero-width epirange only produces results for one as_of (plus no column for which as_of it came from --- note that as_of and issue are not interchangeable). Maybe actually handling epiranges could be made into a separate "enhancement" request issue; for now, maybe we should just reject epiranges and allow only single dates for as_of.

Currently working around for the single-as-of case like this:
  epidatr::covidcast("hhs", "confirmed_admissions_influenza_1d", "day", geo_type,
                     epidatr::epirange(format(target_date_range[[1L]], "%Y%m%d"),
                                       format(target_date_range[[2L]], "%Y%m%d")),
                     geo_values,
                     as_of=epidatr::epirange(format(evaluation_as_of, "%Y%m%d"),
                                             format(evaluation_as_of, "%Y%m%d"))
                     ) %>%
    epidatr::fetch_tbl()
library(epidatr)
library(magrittr)
generates_misleading_error =
  epidatr::covidcast("hhs", "confirmed_admissions_influenza_1d",
                     "day", "nation",
                     epidatr::epirange("20220801", "20220809"),
                     as_of = as.Date("2022-09-09"),
                     "us") %>%
  fetch_tbl()
#> Error in `check_single_epirange_param()`:
#> ! argument as_of is not a epirange
works_but_could_be_shorter =
  epidatr::covidcast("hhs", "confirmed_admissions_influenza_1d",
                     "day", "nation",
                     epidatr::epirange("20220801", "20220809"),
                     as_of = format(as.Date("2022-09-09"), "%Y%m%d"),
                     "us") %>%
  fetch_tbl()
wrong =
  epidatr::covidcast("hhs", "confirmed_admissions_influenza_1d",
                     "day", "nation",
                     epidatr::epirange("20220801", "20220809"),
                     as_of = epidatr::epirange(
                       format(as.Date("2022-09-09"), "%Y%m%d"),
                       format(as.Date("2022-09-20"), "%Y%m%d")
                     ),
                     "us") %>%
  fetch_tbl()
all.equal(works_but_could_be_shorter, wrong) # TRUE is bad
#> [1] TRUE

Created on 2022-09-27 by the reprex package (v2.0.1)

@brookslogan brookslogan added the bug Something isn't working label Sep 27, 2022
@brookslogan brookslogan changed the title covidcast's as_of should not require an epirange, and does not properly handle epiranges covidcast's as_of should not "require" an epirange, and does not properly handle epiranges Sep 27, 2022
@brookslogan brookslogan added the P1 medium priority label Sep 30, 2022
dshemetov added a commit that referenced this issue Apr 24, 2023
@dshemetov dshemetov self-assigned this May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P1 medium priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants