Skip to content

Consolidate fetch interfaces #99

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

Merged
merged 42 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f2566ee
refactor: consolidate fetch interface
dshemetov May 6, 2023
9f3bb2e
docs: document
dshemetov May 6, 2023
c221815
bug: fix epidata error handling and epidatr vignette
dshemetov May 6, 2023
4547219
docs: document
dshemetov May 6, 2023
e94b3c9
bug: fix fetch tests
dshemetov May 6, 2023
56aac93
doc: document
dshemetov May 6, 2023
2e32cf8
bug: add magrittr to suggests
dshemetov May 6, 2023
93fc16b
bug: fix mutate call
dshemetov May 6, 2023
1c03257
feat: change global_base_url to non-proxy host
dshemetov May 11, 2023
670009c
test: Favor `expect_identical` over `expect_equal`; avoid `all_equal`
lcbrooks May 11, 2023
eb4e602
docs: Polish `get_auth_key()` roxygen
lcbrooks May 11, 2023
3939005
tests: Use `withr` in auth tests for better consistency, specificity
lcbrooks May 11, 2023
24eba74
tests: `usethis::use_testthat(edition = 3)` (enforce 3rd edition)
lcbrooks May 11, 2023
8daac67
docs: match style of multiple `@return` entries in `?epidata_call`
lcbrooks May 11, 2023
036f131
refactor: eliminate unused/redundant binding
lcbrooks May 12, 2023
b5d76b7
feat: improve `print.epidata_call` instructions
lcbrooks May 12, 2023
d28a133
docs: describe the two categories of classic $epidata formats
lcbrooks May 12, 2023
ad329f6
docs: fix delphi doc example
dshemetov May 12, 2023
7b89f30
bug: fix no results error code
dshemetov May 12, 2023
0195f11
docs: fix epidata results doc
dshemetov May 12, 2023
e320812
test: fix test comments
dshemetov May 12, 2023
da7199b
refactor: use factor for parsing categoricals
dshemetov May 12, 2023
186a531
refactor: fetch interface
dshemetov May 18, 2023
b1dcea7
style: styler
dshemetov May 18, 2023
4bccc1e
doc: docs
dshemetov May 18, 2023
d83ef0b
bug: fix tests
dshemetov May 18, 2023
53bca8e
docs: update many docstrings
dshemetov May 18, 2023
55ecb3f
refactor(covidcast_epidata): forward HTTP errors
dshemetov May 18, 2023
54e60b3
refactor(fetch): centralize fetch
dshemetov May 18, 2023
162d9ff
refactor(pkg): minor changes
dshemetov May 18, 2023
121fb56
docs: doc
dshemetov May 18, 2023
627eaa6
Merge branch 'dev' into ds/fetch
dshemetov May 18, 2023
f9c9b53
style: styler
dshemetov May 18, 2023
d6f5f89
pkg: set package version to 0.5.0 in constants.R
dshemetov May 18, 2023
9a4971c
refactor: get consistent naming for API request variables
dshemetov May 20, 2023
f06a114
doc: docs
dshemetov May 20, 2023
c151e2c
docs: Fix paragraph-filling that ignored `@param`
lcbrooks May 22, 2023
cf29057
fix: use regular `factor`s, not `ordered`, for `{geo,time}_type`
lcbrooks May 22, 2023
030a60b
docs(as_of): fix typo
lcbrooks May 22, 2023
51814e5
docs(fetch_csv): document new parameters
lcbrooks May 22, 2023
4b6f964
fix: raise warnings from API when able
lcbrooks May 22, 2023
9e97e72
docs: remove docs for replaced `method` parameter
lcbrooks May 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ Imports:
readr,
MMWRweek,
rlang,
magrittr
magrittr,
tibble
RoxygenNote: 7.2.3
Suggests:
knitr,
rmarkdown,
testthat (>= 3.1.5)
testthat (>= 3.1.5),
mockery,
mockr,
dplyr
VignetteBuilder: knitr
Language: en-US
5 changes: 2 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ export(delphi)
export(dengue_nowcast)
export(ecdc_ili)
export(epirange)
export(fetch)
export(fetch_classic)
export(fetch_csv)
export(fetch_json)
export(fetch_tbl)
export(flusurv)
export(fluview)
Expand All @@ -45,7 +44,6 @@ export(pvt_norostat)
export(pvt_quidel)
export(pvt_sensors)
export(pvt_twitter)
export(request_url)
export(wiki)
export(with_base_url)
importFrom(MMWRweek,MMWRweek2Date)
Expand All @@ -72,3 +70,4 @@ importFrom(jsonlite,fromJSON)
importFrom(magrittr,"%>%")
importFrom(readr,read_csv)
importFrom(rlang,abort)
importFrom(tibble,as_tibble)
4 changes: 2 additions & 2 deletions R/auth.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#' Get the API key
#'
#' Get the API key from the environment variable DELPHI_EPIDATA_KEY or getOption("delphi.epidata.key")
#' Get the API key from the environment variable `DELPHI_EPIDATA_KEY` or
#' `getOption("delphi.epidata.key")`.
#'
#' @param verbose Will print the source of the key if TRUE (e.g. options, environment, or config file)
#' @return The API key
#'
#' @export
Expand Down
2 changes: 1 addition & 1 deletion R/constants.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version <- "1.0.0"
http_headers <- httr::add_headers("User-Agent" = paste0("epidatr/", version), "Accept-Encoding" = "gzip")
global_base_url <- "https://delphi.cmu.edu/epidata/"
global_base_url <- "https://api.covidcast.cmu.edu/epidata/"
52 changes: 26 additions & 26 deletions R/endpoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' "fl,ca",
#' epirange(202001, 202110),
#' "flu1,flu2-flu1"
#' ) %>% fetch_tbl()
#' ) %>% fetch()
#' }
#' @export
pvt_afhsb <- function(auth, locations, epiweeks, flu_types) {
Expand Down Expand Up @@ -52,7 +52,7 @@ pvt_afhsb <- function(auth, locations, epiweeks, flu_types) {
#' auth = "yourkey",
#' "fl,ca",
#' epirange(201501, 201601)
#' ) %>% fetch_tbl()
#' ) %>% fetch()
#' }
#' @param auth string. Restricted access key (not the same as API key).
#' @param epiweeks [`timeset`]. Epiweeks to fetch.
Expand Down Expand Up @@ -103,7 +103,7 @@ pvt_cdc <- function(auth, locations, epiweeks) {
#'
#' @examples
#' \donttest{
#' covid_hosp_facility_lookup(state = "fl") %>% fetch_tbl()
#' covid_hosp_facility_lookup(state = "fl") %>% fetch()
#' }
#' @param state string. A two-letter character string state abbreviation.
#' @param ccn string. A character string for facility CMS certification number.
Expand Down Expand Up @@ -172,7 +172,7 @@ covid_hosp_facility_lookup <- function(state = NULL, ccn = NULL, city = NULL, zi
#' covid_hosp_facility(
#' hospital_pks = "100075",
#' collection_weeks = epirange(20200101, 20200501)
#' ) %>% fetch_tbl()
#' ) %>% fetch()
#' }
#' @param hospital_pks string. A character string of facility unique identifiers.
#' @param collection_weeks [`timeset`]. Epiweeks to fetch.
Expand Down Expand Up @@ -461,7 +461,7 @@ covid_hosp_facility <- function(hospital_pks, collection_weeks, publication_date
#' covid_hosp_state_timeseries(
#' states = "fl",
#' dates = epirange(20200101, 20200501)
#' ) %>% fetch_tbl()
#' ) %>% fetch()
#' }
#' @param states character vector. Two letter state abbreviations.
#' @param dates [`timeset`]. Dates to fetch.
Expand Down Expand Up @@ -613,7 +613,7 @@ covid_hosp_state_timeseries <- function(states, dates, issues = NULL) {
#'
#' @examples
#' \donttest{
#' covidcast_meta() %>% fetch_classic()
#' covidcast_meta() %>% fetch()
#' }
#'
#' @seealso [covidcast()]
Expand Down Expand Up @@ -658,7 +658,7 @@ covidcast_meta <- function() {
#' time_type = "day",
#' geo_values = "ca,fl",
#' time_values = epirange(20200601, 20200801)
#' ) %>% fetch_tbl()
#' ) %>% fetch()
#' }
#' @param data_source string. The data source to query (see:
#' <https://cmu-delphi.github.io/delphi-epidata/api/covidcast_signals.html>).
Expand Down Expand Up @@ -766,7 +766,7 @@ covidcast <- function(
#'
#' @examples
#' \donttest{
#' delphi(system = "ec", epiweek = 202006) %>% fetch_classic()
#' delphi(system = "ec", epiweek = 202006) %>% fetch()
#' }
#' @param system string. The system name to fetch.
#' @param epiweek [`timeset`]. The epiweeks to fetch.
Expand Down Expand Up @@ -800,7 +800,7 @@ delphi <- function(system, epiweek) {
#' dengue_nowcast(
#' locations = "?",
#' epiweeks = epirange(201501, 202001)
#' ) %>% fetch_classic()
#' ) %>% fetch()
#' }
#' @param locations character vector. The locations to fetch.
#' @param epiweeks [`timeset`]. The epiweeks to fetch.
Expand Down Expand Up @@ -836,7 +836,7 @@ dengue_nowcast <- function(locations, epiweeks) {
#' names = "?",
#' locations = "?",
#' epiweeks = epirange(201501, 202001)
#' ) %>% fetch_classic()
#' ) %>% fetch()
#' }
#' @param auth string. Restricted access key (not the same as API key).
#' @param names character vector. The list of names to fetch.
Expand Down Expand Up @@ -880,7 +880,7 @@ pvt_dengue_sensors <- function(auth, names, locations, epiweeks) {
#'
#' @examples
#' \donttest{
#' ecdc_ili(regions = "austria", epiweeks = epirange(201901, 202001)) %>% fetch_classic()
#' ecdc_ili(regions = "austria", epiweeks = epirange(201901, 202001)) %>% fetch()
#' }
#' @param regions character vector. The regions to fetch.
#' @param epiweeks [`timeset`]. The epiweeks to fetch.
Expand Down Expand Up @@ -933,7 +933,7 @@ ecdc_ili <- function(regions, epiweeks, issues = NULL, lag = NULL) {
#'
#' @examples
#' \donttest{
#' flusurv(locations = "CA", epiweeks = epirange(201701, 201801)) %>% fetch_classic()
#' flusurv(locations = "CA", epiweeks = epirange(201701, 201801)) %>% fetch()
#' }
#' @param locations character vector. Character strings indicating location.
#' @param epiweeks [`timeset`]. The epiweeks to fetch.
Expand Down Expand Up @@ -985,7 +985,7 @@ flusurv <- function(locations, epiweeks, issues = NULL, lag = NULL) {
#'
#' @examples
#' \donttest{
#' fluview_clinical(regions = "nat", epiweeks = epirange(201601, 201701)) %>% fetch_classic()
#' fluview_clinical(regions = "nat", epiweeks = epirange(201601, 201701)) %>% fetch()
#' }
#' @param regions character vector. The regions to fetch.
#' @param epiweeks [`timeset`]. The epiweeks to fetch in the form epirange(startweek,endweek), where startweek
Expand Down Expand Up @@ -1064,7 +1064,7 @@ fluview_meta <- function() {
#' <https://github.com/cmu-delphi/delphi-epidata/blob/main/src/acquisition/fluview/fluview_locations.py>.
#'
#' @examples
#' fluview(regions = "nat", epiweeks = epirange(201201, 202001)) %>% fetch_classic()
#' fluview(regions = "nat", epiweeks = epirange(201201, 202001)) %>% fetch()
#' @param regions character vector. The locations to fetch. Can we any string IDs in national, HHS region,
#' census division, most states and territories, and so on. Full list link below.
#' @param epiweeks [`timeset`]. The epiweeks to fetch in the form epirange(startweek,endweek), where startweek
Expand Down Expand Up @@ -1132,7 +1132,7 @@ fluview <- function(regions, epiweeks, issues = NULL, lag = NULL, auth = NULL) {
#'
#' @examples
#' \dontrun{
#' gft(locations = "hhs1", epiweeks = epirange(201201, 202001)) %>% fetch_classic()
#' gft(locations = "hhs1", epiweeks = epirange(201201, 202001)) %>% fetch()
#' }
#' @param locations character vector. The locations to be fetched.
#' @param epiweeks [`timeset`] The epiweeks to be fetched.
Expand Down Expand Up @@ -1168,7 +1168,7 @@ gft <- function(locations, epiweeks) {
#' locations = "ca",
#' epiweeks = epirange(201201, 202001),
#' query = "?"
#' ) %>% fetch_classic()
#' ) %>% fetch()
#' }
#' @param auth string. Restricted access key (not the same as API key).
#' @param locations character vector. The locations to be fetched.
Expand Down Expand Up @@ -1207,7 +1207,7 @@ pvt_ght <- function(auth, locations, epiweeks, query) {
#' TODO: find a non-trivial region
#' @examples
#' \dontrun{
#' kcdc_ili(regions = "?", epiweeks = epirange(201201, 202001)) %>% fetch_tbl()
#' kcdc_ili(regions = "?", epiweeks = epirange(201201, 202001)) %>% fetch()
#' }
#' @param regions character vector. The regions to be fetched.
#' @param epiweeks [`timeset`]. The epiweeks to be fetched.
Expand Down Expand Up @@ -1299,7 +1299,7 @@ meta <- function() {
#'
#' @examples
#' \donttest{
#' nidss_dengue(locations = "taipei", epiweeks = epirange(201201, 201301)) %>% fetch_classic()
#' nidss_dengue(locations = "taipei", epiweeks = epirange(201201, 201301)) %>% fetch()
#' }
#' @param locations character vector. The locations to fetch.
#' @param epiweeks [`timeset`]. The epiweeks to fetched.
Expand Down Expand Up @@ -1331,7 +1331,7 @@ nidss_dengue <- function(locations, epiweeks) {
#'
#' @examples
#' \donttest{
#' nidss_flu(regions = "taipei", epiweeks = epirange(201501, 201601)) %>% fetch_classic()
#' nidss_flu(regions = "taipei", epiweeks = epirange(201501, 201601)) %>% fetch()
#' }
#' @param regions character vector. The regions to fetch.
#' @param epiweeks [`timeset`]. The epiweeks to fetch.
Expand Down Expand Up @@ -1385,7 +1385,7 @@ nidss_flu <- function(regions, epiweeks, issues = NULL, lag = NULL) {
#' auth = "yourkey",
#' locations = "Minnesota, Ohio, Oregon, Tennessee, and Wisconsin",
#' epiweeks = epirange(201401, 201501)
#' ) %>% fetch_classic()
#' ) %>% fetch()
#' }
#' @param auth string. Your authentication key.
#' @param locations character vector. The locations to fetch.
Expand Down Expand Up @@ -1425,7 +1425,7 @@ pvt_norostat <- function(auth, locations, epiweeks) {
#'
#' @examples
#' \donttest{
#' nowcast(locations = "ca", epiweeks = epirange(201201, 201301)) %>% fetch_classic()
#' nowcast(locations = "ca", epiweeks = epirange(201201, 201301)) %>% fetch()
#' }
#' @param locations character vector. The locations to fetch.
#' @param epiweeks [`timeset`]. The epiweeks to fetch.
Expand Down Expand Up @@ -1455,7 +1455,7 @@ nowcast <- function(locations, epiweeks) {
#'
#' @examples
#' \donttest{
#' paho_dengue(regions = "ca", epiweeks = epirange(201401, 201501)) %>% fetch_classic()
#' paho_dengue(regions = "ca", epiweeks = epirange(201401, 201501)) %>% fetch()
#' }
#' @param regions character vector. The regions to fetch.
#' @param epiweeks [`timeset`]. The epiweeks to fetch.
Expand Down Expand Up @@ -1508,7 +1508,7 @@ paho_dengue <- function(regions, epiweeks, issues = NULL, lag = NULL) {
#' auth = "yourkey",
#' epiweeks = epirange(201201, 202001),
#' locations = "hhs1"
#' ) %>% fetch_classic()
#' ) %>% fetch()
#' }
#' @param auth string. Restricted access key (not the same as API key).
#' @param locations character vector. The locations to fetch.
Expand Down Expand Up @@ -1548,7 +1548,7 @@ pvt_quidel <- function(auth, locations, epiweeks) {
#' names = "sar3",
#' locations = "nat",
#' epiweeks = epirange(201501, 202001)
#' ) %>% fetch_classic()
#' ) %>% fetch()
#' }
#' @param auth string. Restricted access key (not the same as API key).
#' @param names character vector. The names of the sensors to fetch.
Expand Down Expand Up @@ -1587,7 +1587,7 @@ pvt_sensors <- function(auth, names, locations, epiweeks) {
#'
#' @examples
#' \dontrun{
#' pvt_twitter(auth = "yourkey", locations = "CA", epiweeks = epirange(201501, 202001)) %>% fetch_tbl()
#' pvt_twitter(auth = "yourkey", locations = "CA", epiweeks = epirange(201501, 202001)) %>% fetch()
#' }
#' @param auth string. Restricted access key (not the same as API key).
#' @param locations character vector. The locations to fetch.
Expand Down Expand Up @@ -1636,7 +1636,7 @@ pvt_twitter <- function(auth, locations, dates = NULL, epiweeks = NULL) {
#'
#' @examples
#' \donttest{
#' wiki(articles = "avian_influenza", epiweeks = epirange(201501, 201601)) %>% fetch_tbl()
#' wiki(articles = "avian_influenza", epiweeks = epirange(201501, 201601)) %>% fetch()
#' }
#' @param articles character vector. The articles to fetch.
#' @param dates [`timeset`]. The dates to fetch. Mutually exclusive with `epiweeks`.
Expand Down
Loading