Skip to content
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

Improve error message / output when requesting multiple lags in covidcast::covidcast_signals #578

Open
brookslogan opened this issue Jan 17, 2022 · 0 comments

Comments

@brookslogan
Copy link
Collaborator

It appears that the query composer expects lag to be scalar, but covidcast_signals does not check this, and the error message when feeding in vector/multiple lags isn't immediately clear. (Although the docs for covidcast_signals do state that lag should be an "integer".)

library("pipeR")
library("tidyverse")
library("covidcast")

analysis.date = as.Date("2022-01-17")

signal.descriptions = tribble(
  ~data_source, ~signal, ~dual_lag,
  "jhu-csse", "confirmed_7dav_incidence_prop", 1L,
  "jhu-csse", "confirmed_7dav_incidence_prop", 8L,
  "fb-survey", "smoothed_hh_cmnty_cli", 1L,
  "fb-survey", "smoothed_hh_cmnty_cli", 8L,
  "doctor-visits", "smoothed_adj_cli", 1L,
  "doctor-visits", "smoothed_adj_cli", 8L,
  "quidel", "covid_ag_smoothed_pct_positive", 1L,
  "quidel", "covid_ag_smoothed_pct_positive", 8L,
  )

signal.dfs = covidcast_signals(
  data_source = signal.descriptions[["data_source"]],
  signal = signal.descriptions[["signal"]],
  lag = signal.descriptions[["dual_lag"]],
  geo_type = "state",
  as_of=analysis.date
) %>>%
  map2(function(signal.df, dual.lag) {
    signal.df %>>%
      mutate(time_value = time_value + dual.lag)
  })

Output:

Error in vapply(elements, encode, character(1)) : 
  values must be length 1,
 but FUN(X[[10]]) result is length 8

Investigation via "recover":

Enter a frame number, or 0 to exit   

 1: covidcast_signals(data_source = signal.descriptions[["data_source"]], signa
 2: covidcast_signals(data_source = signal.descriptions[["data_source"]], signa
 3: covidcast_signal(data_source = data_source[i], signal = signal[i], start_da
 4: covidcast_days(data_source, signal, start_day, end_day, geo_type, geo_value
 5: covidcast(data_source = data_source, signal = signal, time_type = time_type
 6: .request(params)
 7: httr::GET(getOption("covidcast.base_url", default = COVIDCAST_BASE_URL), ht
 8: handle_url(handle, url, ...)
 9: build_url(utils::modifyList(old, new))
10: compose_query(compact(url$query))
11: vapply(elements, encode, character(1))

Selection: Enter an item from the menu, or 0 to exit
Selection: 11
Called from: top level 
Browse[1]> ls()
[1] "FUN"       "FUN.VALUE" "i"         "USE.NAMES" "X"        
Browse[1]> X
$source
[1] "covidcast"

$data_source
[1] "jhu-csse"

$signal
[1] "confirmed_7dav_incidence_prop"

$time_type
[1] "day"

$geo_type
[1] "state"

$time_values
[1] "20200220, 20200221, 20200222, 20200223, 20200224, 20200225, 20200226, 20200227, 20200228, 20200229, 20200301, 20200302, 20200303, 20200304, 20200305, 20200306, 20200307, 20200308, 20200309, 20200310, 20200311, 20200312, 20200313, 20200314, 20200315, 20200316, 20200317, 20200318, 20200319, 20200320, 20200321, 20200322, 20200323, 20200324, 20200325, 20200326, 20200327, 20200328, 20200329, 20200330, 20200331, 20200401, 20200402, 20200403, 20200404, 20200405, 20200406, 20200407, 20200408, 20200409, 20200410, 20200411, 20200412, 20200413, 20200414, 20200415, 20200416, 20200417, 20200418, 20200419, 20200420, 20200421, 20200422, 20200423, 20200424"

$geo_value
[1] "*"

$format
[1] "csv"

$as_of
[1] "20220117"

$lag
[1] 1 8 1 8 1 8 1 8

Browse[1]> 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants