Skip to content

Consider allowing Dates in place of epiranges, Dates & hyphenated datestrings in epiranges #47

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 · 1 comment
Assignees
Labels
enhancement New feature or request P0 Top priority

Comments

@brookslogan
Copy link
Contributor

brookslogan commented Sep 27, 2022

Currently, Date objects cannot be fed in as, e.g., time_values to epidatr::covidcast, as Date objects are not considered epirange-like, nor can they be used successfully as the endpoints of an epirange. This is an inconvenience, as often we do Date-based arithmetic or use Sys.Date() to arrive at time_values of interest, and, furthermore, simply using as.character or toString doesn't always put them in the accepted format. (The hyphenated-string handling might require a little care due to hyphens being allowed to represent ranges between non-hyphenated-datestrings; hyphenated strings probably will need converted to non-hyphenated strings somewhere, and probably already are in the situations where they already work.)

It'd be nice for all, not just some, of the queries below to work. [Providing more comprehensible and helpful error messages, if easier, could be a temporary patch (--- e.g., suggesting to use format(dates, "%Y%m%d")).]

library(epidatr)
library(magrittr)
covidcast("hhs", "confirmed_admissions_covid_1d_prop", "day", "nation",
          "20220101", "*") %>% fetch_tbl()
#> # A tibble: 1 × 15
#>   geo_value signal    source geo_t…¹ time_…² time_value direc…³ issue        lag
#>   <chr>     <chr>     <chr>  <ord>   <ord>   <date>       <dbl> <date>     <int>
#> 1 us        confirme… hhs    nation  day     2022-01-01      NA 2022-03-23    81
#> # … with 6 more variables: missing_value <int>, missing_stderr <int>,
#> #   missing_sample_size <int>, value <dbl>, stderr <dbl>, sample_size <dbl>,
#> #   and abbreviated variable names ¹​geo_type, ²​time_type, ³​direction
#> # ℹ Use `colnames()` to see all variable names
covidcast("hhs", "confirmed_admissions_covid_1d_prop", "day", "nation",
          c("20220101","20220102"), "*") %>% fetch_tbl()
#> # A tibble: 2 × 15
#>   geo_value signal    source geo_t…¹ time_…² time_value direc…³ issue        lag
#>   <chr>     <chr>     <chr>  <ord>   <ord>   <date>       <dbl> <date>     <int>
#> 1 us        confirme… hhs    nation  day     2022-01-01      NA 2022-03-23    81
#> 2 us        confirme… hhs    nation  day     2022-01-02      NA 2022-07-10   189
#> # … with 6 more variables: missing_value <int>, missing_stderr <int>,
#> #   missing_sample_size <int>, value <dbl>, stderr <dbl>, sample_size <dbl>,
#> #   and abbreviated variable names ¹​geo_type, ²​time_type, ³​direction
#> # ℹ Use `colnames()` to see all variable names
covidcast("hhs", "confirmed_admissions_covid_1d_prop", "day", "nation",
          "20220101-20220105", "*") %>% fetch_tbl()
#> # A tibble: 5 × 15
#>   geo_value signal    source geo_t…¹ time_…² time_value direc…³ issue        lag
#>   <chr>     <chr>     <chr>  <ord>   <ord>   <date>       <dbl> <date>     <int>
#> 1 us        confirme… hhs    nation  day     2022-01-01      NA 2022-03-23    81
#> 2 us        confirme… hhs    nation  day     2022-01-02      NA 2022-07-10   189
#> 3 us        confirme… hhs    nation  day     2022-01-03      NA 2022-03-23    79
#> 4 us        confirme… hhs    nation  day     2022-01-04      NA 2022-08-04   212
#> 5 us        confirme… hhs    nation  day     2022-01-05      NA 2022-03-23    77
#> # … with 6 more variables: missing_value <int>, missing_stderr <int>,
#> #   missing_sample_size <int>, value <dbl>, stderr <dbl>, sample_size <dbl>,
#> #   and abbreviated variable names ¹​geo_type, ²​time_type, ³​direction
#> # ℹ Use `colnames()` to see all variable names
covidcast("hhs", "confirmed_admissions_covid_1d_prop", "day", "nation",
          epirange("20220101","20220105"), "*") %>% fetch_tbl()
#> # A tibble: 5 × 15
#>   geo_value signal    source geo_t…¹ time_…² time_value direc…³ issue        lag
#>   <chr>     <chr>     <chr>  <ord>   <ord>   <date>       <dbl> <date>     <int>
#> 1 us        confirme… hhs    nation  day     2022-01-01      NA 2022-03-23    81
#> 2 us        confirme… hhs    nation  day     2022-01-02      NA 2022-07-10   189
#> 3 us        confirme… hhs    nation  day     2022-01-03      NA 2022-03-23    79
#> 4 us        confirme… hhs    nation  day     2022-01-04      NA 2022-08-04   212
#> 5 us        confirme… hhs    nation  day     2022-01-05      NA 2022-03-23    77
#> # … with 6 more variables: missing_value <int>, missing_stderr <int>,
#> #   missing_sample_size <int>, value <dbl>, stderr <dbl>, sample_size <dbl>,
#> #   and abbreviated variable names ¹​geo_type, ²​time_type, ³​direction
#> # ℹ Use `colnames()` to see all variable names
covidcast("hhs", "confirmed_admissions_covid_1d_prop", "day", "nation",
          "2022-01-01", "*") %>% fetch_tbl()
#> # A tibble: 1 × 15
#>   geo_value signal    source geo_t…¹ time_…² time_value direc…³ issue        lag
#>   <chr>     <chr>     <chr>  <ord>   <ord>   <date>       <dbl> <date>     <int>
#> 1 us        confirme… hhs    nation  day     2022-01-01      NA 2022-03-23    81
#> # … with 6 more variables: missing_value <int>, missing_stderr <int>,
#> #   missing_sample_size <int>, value <dbl>, stderr <dbl>, sample_size <dbl>,
#> #   and abbreviated variable names ¹​geo_type, ²​time_type, ³​direction
#> # ℹ Use `colnames()` to see all variable names
covidcast("hhs", "confirmed_admissions_covid_1d_prop", "day", "nation",
          c("2022-01-01", "2022-01-02"), "*") %>% fetch_tbl()
#> # A tibble: 2 × 15
#>   geo_value signal    source geo_t…¹ time_…² time_value direc…³ issue        lag
#>   <chr>     <chr>     <chr>  <ord>   <ord>   <date>       <dbl> <date>     <int>
#> 1 us        confirme… hhs    nation  day     2022-01-01      NA 2022-03-23    81
#> 2 us        confirme… hhs    nation  day     2022-01-02      NA 2022-07-10   189
#> # … with 6 more variables: missing_value <int>, missing_stderr <int>,
#> #   missing_sample_size <int>, value <dbl>, stderr <dbl>, sample_size <dbl>,
#> #   and abbreviated variable names ¹​geo_type, ²​time_type, ³​direction
#> # ℹ Use `colnames()` to see all variable names
covidcast("hhs", "confirmed_admissions_covid_1d_prop", "day", "nation",
          epirange("2022-01-01", "2022-01-05"), "*") %>% fetch_tbl()
#> Error: '' does not exist in current working directory ('/tmp/RtmpFtrhOX/reprex-20de19cb4198-prior-boa').
covidcast("hhs", "confirmed_admissions_covid_1d_prop", "day", "nation",
          epirange("2022-01-01", "2022-01-05"), "*") %>% fetch_tbl()
#> Error: '' does not exist in current working directory ('/tmp/RtmpFtrhOX/reprex-20de19cb4198-prior-boa').
date = as.Date("2022-01-05")
covidcast("hhs", "confirmed_admissions_covid_1d_prop", "day", "nation",
          date, "*") %>% fetch_tbl()
#> Error in !is.list: invalid argument type
# (the weird error message here is from #46) 
covidcast("hhs", "confirmed_admissions_covid_1d_prop", "day", "nation",
          c(date, date+1L), "*") %>% fetch_tbl()
#> Error in !is.list: invalid argument type
# (the weird error message here is from #46) 
n_days = 5L
covidcast("hhs", "confirmed_admissions_covid_1d_prop", "day", "nation",
          epirange(date, date + n_days - 1L), "*") %>% fetch_tbl()
#> Error in epirange(date, date + n_days - 1L): (is.numeric(from) || is.character(from)) && length(from) == 1 is not TRUE

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

@dshemetov
Copy link
Contributor

fixed by #89

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P0 Top priority
Projects
None yet
Development

No branches or pull requests

2 participants