diff --git a/DESCRIPTION b/DESCRIPTION index db218ca5..c33e6b1f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,7 +9,7 @@ Authors@R: person("David", "Weber", email = "davidweb@andrew.cmu.edu", role = c("ctb")), person("Samuel", "Gratzl", email = "sam@sgratzl.com", role = c("aut")) ) -URL: https://github.com/cmu-delphi/epidatr +URL: https://cmu-delphi.github.io/epidatr/, https://github.com/cmu-delphi/epidatr BugReports: https://github.com/cmu-delphi/epidatr/issues Description: R Client for Delphi's Epidata API. Tools for fetching data in various forms. Depends: R (>= 3.5.0) diff --git a/NAMESPACE b/NAMESPACE index d8e4ef3e..b6041fb3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,6 +10,7 @@ export(covid_hosp_facility) export(covid_hosp_facility_lookup) export(covid_hosp_state_timeseries) export(covidcast) +export(covidcast_epidata) export(covidcast_meta) export(delphi) export(dengue_nowcast) diff --git a/R/check.R b/R/check.R index 3878f5b1..87d9825c 100644 --- a/R/check.R +++ b/R/check.R @@ -34,6 +34,7 @@ assert_date_param <- function(name, value, len = NULL, required = TRUE) { #' Allows a timeset param: a date vector, a character vector, an integer-like #' vector, or a single EpiRange #' @importFrom checkmate assert check_character check_date check_integerish check_class check_list check_names +#' @keywords internal assert_timeset_param <- function(name, value, len = NULL, required = TRUE) { null.ok <- !required assert_integerish(len, len = 1L, null.ok = TRUE, .var.name = "len") diff --git a/R/covidcast.R b/R/covidcast.R index a818018b..3ff1a912 100644 --- a/R/covidcast.R +++ b/R/covidcast.R @@ -14,6 +14,7 @@ parse_signal <- function(signal, base_url) { #' @param issues data source to fetch #' @param lag data source to fetch #' @return an instance of epidata_call + #' @keywords internal signal$call <- function(geo_type, geo_values, time_values, @@ -31,10 +32,10 @@ parse_signal <- function(signal, base_url) { } #' @export -print.covidcast_data_signal <- function(signal, ...) { - print(signal$name) - print(signal$key) - print(signal$short_description) +print.covidcast_data_signal <- function(x, ...) { + print(x$name) + print(x$key) + print(x$short_description) } parse_source <- function(source, base_url) { @@ -78,17 +79,17 @@ as.data.frame.covidcast_data_signal_list <- function(signals, ...) { } #' @export -print.covidcast_data_source <- function(source, ...) { - print(source$name, ...) - print(source$source, ...) - print(source$description, ...) - signals <- as.data.frame(source$signals) +print.covidcast_data_source <- function(x, ...) { + print(x$name, ...) + print(x$source, ...) + print(x$description, ...) + signals <- as.data.frame(x$signals) print(signals[, c("signal", "name", "short_description")], ...) } -#' creates the covidcast epidata helper +#' Creates the COVIDcast Epidata autocomplete helper #' -#' Creates a helper object that can use auto-complete to help find covidcast +#' Creates a helper object that can use auto-complete to help find COVIDcast #' sources and signals. #' #' @param base_url optional alternative API base url @@ -96,8 +97,8 @@ print.covidcast_data_source <- function(source, ...) { #' @importFrom httr stop_for_status content http_type #' @importFrom jsonlite fromJSON #' @importFrom xml2 read_html xml_find_all xml_text -#' @return an instance of covidcast_epidata -#' +#' @return An instance of `covidcast_epidata` +#' @export covidcast_epidata <- function(base_url = global_base_url, timeout_seconds = 30) { url <- join_url(base_url, "covidcast/meta") response <- do_request(url, list(), timeout_seconds) @@ -154,16 +155,16 @@ as.data.frame.covidcast_data_source_list <- function(sources, ...) { }), ...) } -print.covidcast_epidata <- function(epidata, ...) { +print.covidcast_epidata <- function(x, ...) { print("COVIDcast Epidata Fetcher") print("Sources:") - sources <- as.data.frame(epidata$sources) + sources <- as.data.frame(x$sources) print(sources[1:5, c("source", "name")], ...) if (nrow(sources) > 5) { print(paste0((nrow(sources) - 5), " more...")) } print("Signals") - signals <- as.data.frame(epidata$signals) + signals <- as.data.frame(x$signals) print(signals[1:5, c("source", "signal", "name")], ...) if (nrow(signals) > 5) { print(paste0((nrow(signals) - 5), " more...")) diff --git a/R/endpoints.R b/R/endpoints.R index 3861c0a4..239dc220 100644 --- a/R/endpoints.R +++ b/R/endpoints.R @@ -1,6 +1,6 @@ #' Fetch CDC page hits #' -#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/cdc.html +#' API docs: #' #' @examples #' \dontrun{ @@ -640,10 +640,10 @@ covidcast_meta <- function() { #' time_values = epirange(20200601, 20200801) #' ) %>% fetch() #' } -#' @param data_source string. The data source to query (see: +#' @param source string. The data source to query (see: #' ). #' @param signals string. The signals to query from a specific source (see: -#' ). +#' ). #' @param geo_type string. The geographic resolution of the data (see: #' ). #' @param time_type string. The temporal resolution of the data (either "day" or @@ -685,7 +685,7 @@ covidcast <- function( missing(time_values) || missing(geo_values) ) { stop( - "`data_source`, `signals`, `time_type`, `geo_type`, `time_values`, and `geo_value` are all required" + "`source`, `signals`, `time_type`, `geo_type`, `time_values`, and `geo_value` are all required" ) } @@ -748,7 +748,7 @@ covidcast <- function( #' Fetch Delphi's ILINet forecasts #' -#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/delphi.html +#' API docs: #' #' @examples #' \dontrun{ @@ -778,7 +778,7 @@ delphi <- function(system, epiweek) { #' Fetch Delphi's PAHO Dengue nowcast #' -#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/dengue_nowcast.html +#' API docs: #' #' TODO: what are valid locations here? #' @examples @@ -813,7 +813,7 @@ dengue_nowcast <- function(locations, epiweeks) { #' Fetch Delphi's digital surveillance sensors for dengue in PAHO member #' countries #' -#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/dengue_sensors.html +#' API docs: #' #' TODO: what are valid locations and names? #' @examples @@ -970,7 +970,7 @@ flusurv <- function(locations, epiweeks, issues = NULL, lag = NULL) { #' Fetch FluView virological data from clinical labs #' -#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/fluview_clinical.html +#' API docs: #' #' @examples #' \dontrun{ @@ -1024,7 +1024,7 @@ fluview_clinical <- function(regions, epiweeks, issues = NULL, lag = NULL) { #' Fetch FluView metadata #' -#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/fluview_meta.html +#' API docs: #' @examples #' \dontrun{ #' fluview_meta() %>% fetch() @@ -1159,7 +1159,7 @@ gft <- function(locations, epiweeks) { #' Fetch Google Health Trends data #' -#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/ght.html +#' API docs: #' #' TODO: find a non-trivial query #' @examples @@ -1203,7 +1203,7 @@ pvt_ght <- function(auth, locations, epiweeks, query) { #' Fetch KCDC data #' -#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/kcdc_ili.html +#' API docs: #' #' TODO: find a non-trivial region #' @examples @@ -1251,7 +1251,7 @@ kcdc_ili <- function(regions, epiweeks, issues = NULL, lag = NULL) { #' Fetch NoroSTAT metadata #' -#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/meta_norostat.html +#' API docs: #' #' @examples #' \dontrun{ @@ -1269,7 +1269,7 @@ pvt_meta_norostat <- function(auth) { #' Fetch api metadata #' -#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/meta.html +#' API docs: #' #' @return [`epidata_call`] #' @@ -1371,7 +1371,7 @@ nidss_flu <- function(regions, epiweeks, issues = NULL, lag = NULL) { #' Fetch NoroSTAT data (point data, no min/max) #' -#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/norostat.html +#' API docs: #' #' @examples #' \dontrun{ @@ -1446,7 +1446,7 @@ nowcast <- function(locations, epiweeks) { #' Fetch PAHO Dengue #' -#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/paho_dengue.html +#' API docs: #' #' @examples #' \dontrun{ @@ -1495,7 +1495,7 @@ paho_dengue <- function(regions, epiweeks, issues = NULL, lag = NULL) { #' Fetch Quidel COVID-19 and influenza testing data #' -#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/quidel.html +#' API docs: #' #' @examples #' \dontrun{ @@ -1534,7 +1534,7 @@ pvt_quidel <- function(auth, locations, epiweeks) { #' Fetch Delphi's digital surveillance sensors #' -#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/sensors.html +#' API docs: #' #' @examples #' \dontrun{ @@ -1578,7 +1578,7 @@ pvt_sensors <- function(auth, names, locations, epiweeks) { #' Fetch HealthTweets data #' -#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/twitter.html +#' API docs: #' #' @examples #' \dontrun{ @@ -1628,7 +1628,7 @@ pvt_twitter <- function(auth, locations, dates = NULL, epiweeks = NULL) { #' Fetch Wikipedia access data #' -#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/wiki.html +#' API docs: #' #' @examples #' \dontrun{ diff --git a/R/epidatacall.R b/R/epidatacall.R index 6017037d..1e5fd818 100644 --- a/R/epidatacall.R +++ b/R/epidatacall.R @@ -89,12 +89,12 @@ request_arguments <- function(epidata_call, format_type, fields = NULL) { } #' @export -print.epidata_call <- function(epidata_call) { - stopifnot(inherits(epidata_call, "epidata_call")) +print.epidata_call <- function(x, ...) { + stopifnot(inherits(x, "epidata_call")) cli::cli_h1(" object:") cli::cli_bullets(c( "*" = "Pipe this object into `fetch()` to actually fetch the data", - "*" = paste0("Request URL: ", request_url(epidata_call)) + "*" = paste0("Request URL: ", request_url(x)) )) } @@ -264,6 +264,7 @@ with_base_url <- function(epidata_call, base_url) { #' HTTP errors and forwarding the HTTP body in R errors #' @importFrom httr stop_for_status content http_type #' @importFrom xml2 read_html xml_find_all xml_text +#' @keywords internal request_impl <- function(epidata_call, format_type, fields = NULL, timeout_seconds = 30) { stopifnot(inherits(epidata_call, "epidata_call")) stopifnot(format_type %in% c("json", "csv", "classic")) diff --git a/R/epidatr-package.R b/R/epidatr-package.R index 40d61673..0cc9debe 100644 --- a/R/epidatr-package.R +++ b/R/epidatr-package.R @@ -1,7 +1,2 @@ -#' Delphi Epidata -#' -#' TODO -#' -#' @docType package -#' @name epidatr -NULL +#' @keywords internal +"_PACKAGE" diff --git a/R/model.R b/R/model.R index b2b844f5..650f06f3 100644 --- a/R/model.R +++ b/R/model.R @@ -1,12 +1,25 @@ -#' builds a new EpiRange instances +#' Specify a date range (in days or epiweeks) for an API request. #' -#' @param from A Date, integer-like value, or integer-like string that takes the -#' form YYYYMMDD for dates or YYYYMM for epiweeks. -#' @param to A Date, integer-like value, or integer-like string that takes the -#' form YYYYMMDD for dates or YYYYMM for epiweeks. +#' Epiweeks, also known as MMWR weeks number the weeks of the year from 1 to 53, +#' each week spanning from Sunday to Saturday. The numbering is [defined by the +#' CDC](https://ndc.services.cdc.gov/wp-content/uploads/MMWR_Week_overview.pdf). +#' +#' @param from A `Date`, integer-like value, or integer-like string that takes the +#' form YYYYMMDD for dates or YYYYWW for epiweeks. +#' @param to A `Date`, integer-like value, or integer-like string that takes the +#' form YYYYMMDD for dates or YYYYWW for epiweeks. #' @return EpiRange instance #' @importFrom checkmate check_integerish check_character check_date assert #' +#' @examples +#' # Represents 2021-01-01 to 2021-01-07, inclusive +#' epirange(20210101, 20210107) +#' +#' # The same, but using Date objects +#' epirange(as.Date("2021-01-01"), as.Date("2021-01-07")) +#' +#' # Represents epiweeks 2 through 4 of 2022, inclusive +#' epirange(202202, 202204) #' @export epirange <- function(from, to) { assert( @@ -47,21 +60,25 @@ epirange <- function(from, to) { #' timeset #' -#' A collection of date-like values, including dates, epiweeks, and ranges of -#' dates or epiweeks ([`epirange`]). This is often used to specify the time -#' dimension for an epidata query. The allowed values are: +#' Many API calls accept timesets to specify the time ranges of data being +#' requested. Timesets can be specified with `epirange()`, as `Date` objects, or +#' with wildcards. +#' +#' Timesets are not special R types; the term simply describes any value that +#' would be accepted by epidatr to specify the time value of an epidata query. +#' The allowed values are: #' #' - Dates: `Date` instances, integer-like values, or integer-like strings that -#' take the form YYYYMMDD, -#' - Epiweeks: integer-like values or integer-like strings that take the form -#' YYYYMM, -#' - EpiRanges: a list of [`epirange`] instances. -#' - Wildcard: "*" (requests all available values for this dimension) +#' take the form YYYYMMDD. +#' - Epiweeks: Integer-like values or integer-like strings that take the form +#' YYYYWW. +#' - EpiRanges: A range returned by `epirange()`, or a list of multiple ranges +#' - Wildcard: The string `"*"`, which request all available time values #' #' Please refer to the specific endpoint documentation for guidance on using #' dates vs weeks. Most endpoints support only one or the other. Some (less #' commonly used) endpoints may not accept the `"*"` wildcard, but this can be -#' simulated with a large [`epirange`]. +#' simulated with a large `epirange()`. #' #' @name timeset NULL diff --git a/R/request.R b/R/request.R index 71a99149..aad79074 100644 --- a/R/request.R +++ b/R/request.R @@ -21,6 +21,7 @@ join_url <- function(url, endpoint) { #' } #' #' @importFrom httr RETRY +#' @keywords internal do_request <- function(url, params, timeout_seconds = 30) { # don't retry in case of certain status codes res <- httr::RETRY("GET", diff --git a/_pkgdown.yml b/_pkgdown.yml index 02ee0f7a..1a3ae552 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -5,3 +5,51 @@ home: - text: View the Delphi Website href: https://delphi.cmu.edu/ + +reference: + - title: Configuration and utilities + desc: Set API keys and handle API data types + - contents: + - get_auth_key + - parse_api_week + - epirange + - timeset + - title: Make API requests + desc: Query Delphi Epidata endpoints + - contents: + - epidata_call + - covid_hosp_facility + - covid_hosp_facility_lookup + - covid_hosp_state_timeseries + - covidcast + - covidcast_meta + - delphi + - dengue_nowcast + - ecdc_ili + - flusurv + - fluview + - fluview_clinical + - fluview_meta + - gft + - kcdc_ili + - meta + - nidss_dengue + - nidss_flu + - nowcast + - paho_dengue + - wiki + - title: Make requests to private API endpoints + desc: These endpoints require additional authorization to use + - contents: + - pvt_cdc + - pvt_dengue_sensors + - pvt_ght + - pvt_meta_norostat + - pvt_norostat + - pvt_quidel + - pvt_sensors + - pvt_twitter + - title: Autocomplete helpers + desc: Objects that can autocomplete API signals names for faster exploration + - contents: + - covidcast_epidata diff --git a/man/assert_timeset_param.Rd b/man/assert_timeset_param.Rd index 218061a1..dc6e4dd2 100644 --- a/man/assert_timeset_param.Rd +++ b/man/assert_timeset_param.Rd @@ -11,3 +11,4 @@ assert_timeset_param(name, value, len = NULL, required = TRUE) Allows a timeset param: a date vector, a character vector, an integer-like vector, or a single EpiRange } +\keyword{internal} diff --git a/man/covidcast.Rd b/man/covidcast.Rd index 8ecc5c0d..941bba9c 100644 --- a/man/covidcast.Rd +++ b/man/covidcast.Rd @@ -17,8 +17,11 @@ covidcast( ) } \arguments{ +\item{source}{string. The data source to query (see: +\url{https://cmu-delphi.github.io/delphi-epidata/api/covidcast_signals.html}).} + \item{signals}{string. The signals to query from a specific source (see: -\url{https://cmu-delphi.github.io/delphi-epidata/api/covidcast-signals.html}).} +\url{https://cmu-delphi.github.io/delphi-epidata/api/covidcast_signals.html}).} \item{geo_type}{string. The geographic resolution of the data (see: \url{https://cmu-delphi.github.io/delphi-epidata/api/covidcast_geography.html}).} @@ -43,9 +46,6 @@ specified, the most recent issue is returned. Mutually exclusive with \item{lag}{integer. Optionally, the lag of the issues to fetch. If not set, the most recent issue is returned. Mutually exclusive with \code{as_of} or \code{issues}.} - -\item{data_source}{string. The data source to query (see: -\url{https://cmu-delphi.github.io/delphi-epidata/api/covidcast_signals.html}).} } \value{ \code{\link{epidata_call}} diff --git a/man/covidcast_epidata.Rd b/man/covidcast_epidata.Rd index 206fb493..6b24cb13 100644 --- a/man/covidcast_epidata.Rd +++ b/man/covidcast_epidata.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/covidcast.R \name{covidcast_epidata} \alias{covidcast_epidata} -\title{creates the covidcast epidata helper} +\title{Creates the COVIDcast Epidata autocomplete helper} \usage{ covidcast_epidata(base_url = global_base_url, timeout_seconds = 30) } @@ -12,9 +12,9 @@ covidcast_epidata(base_url = global_base_url, timeout_seconds = 30) \item{timeout_seconds}{the maximum amount of time to wait for a response} } \value{ -an instance of covidcast_epidata +An instance of \code{covidcast_epidata} } \description{ -Creates a helper object that can use auto-complete to help find covidcast +Creates a helper object that can use auto-complete to help find COVIDcast sources and signals. } diff --git a/man/delphi.Rd b/man/delphi.Rd index 7d74f70d..e7baf732 100644 --- a/man/delphi.Rd +++ b/man/delphi.Rd @@ -15,7 +15,7 @@ delphi(system, epiweek) \code{\link{epidata_call}} } \description{ -API docs: https://cmu-delphi.github.io/delphi-epidata/api/delphi.html +API docs: \url{https://cmu-delphi.github.io/delphi-epidata/api/delphi.html} } \examples{ \dontrun{ diff --git a/man/dengue_nowcast.Rd b/man/dengue_nowcast.Rd index c03a6020..85a60314 100644 --- a/man/dengue_nowcast.Rd +++ b/man/dengue_nowcast.Rd @@ -15,7 +15,7 @@ dengue_nowcast(locations, epiweeks) \code{\link{epidata_call}} } \description{ -API docs: https://cmu-delphi.github.io/delphi-epidata/api/dengue_nowcast.html +API docs: \url{https://cmu-delphi.github.io/delphi-epidata/api/dengue_nowcast.html} } \details{ TODO: what are valid locations here? diff --git a/man/do_request.Rd b/man/do_request.Rd index 4584e40e..7add7b85 100644 --- a/man/do_request.Rd +++ b/man/do_request.Rd @@ -22,3 +22,4 @@ content(response)$headers$Authorization == paste0( } } +\keyword{internal} diff --git a/man/epidatr-package.Rd b/man/epidatr-package.Rd new file mode 100644 index 00000000..7069c2f1 --- /dev/null +++ b/man/epidatr-package.Rd @@ -0,0 +1,35 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/epidatr-package.R +\docType{package} +\name{epidatr-package} +\alias{epidatr} +\alias{epidatr-package} +\title{epidatr: Client for Delphi's Epidata API} +\description{ +R Client for Delphi's Epidata API. Tools for fetching data in various forms. +} +\seealso{ +Useful links: +\itemize{ + \item \url{https://cmu-delphi.github.io/epidatr/} + \item \url{https://github.com/cmu-delphi/epidatr} + \item Report bugs at \url{https://github.com/cmu-delphi/epidatr/issues} +} + +} +\author{ +\strong{Maintainer}: Logan Brooks \email{lcbrooks@andrew.cmu.edu} + +Authors: +\itemize{ + \item Dmitry Shemetov \email{dshemeto@andrew.cmu.edu} + \item Samuel Gratzl \email{sam@sgratzl.com} +} + +Other contributors: +\itemize{ + \item David Weber \email{davidweb@andrew.cmu.edu} [contributor] +} + +} +\keyword{internal} diff --git a/man/epidatr.Rd b/man/epidatr.Rd deleted file mode 100644 index b71cbe70..00000000 --- a/man/epidatr.Rd +++ /dev/null @@ -1,9 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/epidatr-package.R -\docType{package} -\name{epidatr} -\alias{epidatr} -\title{Delphi Epidata} -\description{ -TODO -} diff --git a/man/epirange.Rd b/man/epirange.Rd index c0282e54..e1732122 100644 --- a/man/epirange.Rd +++ b/man/epirange.Rd @@ -2,20 +2,31 @@ % Please edit documentation in R/model.R \name{epirange} \alias{epirange} -\title{builds a new EpiRange instances} +\title{Specify a date range (in days or epiweeks) for an API request.} \usage{ epirange(from, to) } \arguments{ -\item{from}{A Date, integer-like value, or integer-like string that takes the -form YYYYMMDD for dates or YYYYMM for epiweeks.} +\item{from}{A \code{Date}, integer-like value, or integer-like string that takes the +form YYYYMMDD for dates or YYYYWW for epiweeks.} -\item{to}{A Date, integer-like value, or integer-like string that takes the -form YYYYMMDD for dates or YYYYMM for epiweeks.} +\item{to}{A \code{Date}, integer-like value, or integer-like string that takes the +form YYYYMMDD for dates or YYYYWW for epiweeks.} } \value{ EpiRange instance } \description{ -builds a new EpiRange instances +Epiweeks, also known as MMWR weeks number the weeks of the year from 1 to 53, +each week spanning from Sunday to Saturday. The numbering is \href{https://ndc.services.cdc.gov/wp-content/uploads/MMWR_Week_overview.pdf}{defined by the CDC}. +} +\examples{ +# Represents 2021-01-01 to 2021-01-07, inclusive +epirange(20210101, 20210107) + +# The same, but using Date objects +epirange(as.Date("2021-01-01"), as.Date("2021-01-07")) + +# Represents epiweeks 2 through 4 of 2022, inclusive +epirange(202202, 202204) } diff --git a/man/fluview_clinical.Rd b/man/fluview_clinical.Rd index 43d82ce0..e2e495ac 100644 --- a/man/fluview_clinical.Rd +++ b/man/fluview_clinical.Rd @@ -23,7 +23,7 @@ the most recent issue is returned. Mutually exclusive with \code{issues}.} \code{\link{epidata_call}} } \description{ -API docs: https://cmu-delphi.github.io/delphi-epidata/api/fluview_clinical.html +API docs: \url{https://cmu-delphi.github.io/delphi-epidata/api/fluview_clinical.html} } \examples{ \dontrun{ diff --git a/man/fluview_meta.Rd b/man/fluview_meta.Rd index af54c4d9..04308b0b 100644 --- a/man/fluview_meta.Rd +++ b/man/fluview_meta.Rd @@ -10,7 +10,7 @@ fluview_meta() \code{\link{epidata_call}} } \description{ -API docs: https://cmu-delphi.github.io/delphi-epidata/api/fluview_meta.html +API docs: \url{https://cmu-delphi.github.io/delphi-epidata/api/fluview_meta.html} } \examples{ \dontrun{ diff --git a/man/kcdc_ili.Rd b/man/kcdc_ili.Rd index fdcd7113..c0c52961 100644 --- a/man/kcdc_ili.Rd +++ b/man/kcdc_ili.Rd @@ -21,7 +21,7 @@ the most recent issue is returned. Mutually exclusive with \code{issues}.} \code{\link{epidata_call}} } \description{ -API docs: https://cmu-delphi.github.io/delphi-epidata/api/kcdc_ili.html +API docs: \url{https://cmu-delphi.github.io/delphi-epidata/api/kcdc_ili.html} } \details{ TODO: find a non-trivial region diff --git a/man/meta.Rd b/man/meta.Rd index ee64d90c..3bd1958d 100644 --- a/man/meta.Rd +++ b/man/meta.Rd @@ -10,5 +10,5 @@ meta() \code{\link{epidata_call}} } \description{ -API docs: https://cmu-delphi.github.io/delphi-epidata/api/meta.html +API docs: \url{https://cmu-delphi.github.io/delphi-epidata/api/meta.html} } diff --git a/man/paho_dengue.Rd b/man/paho_dengue.Rd index 452577ba..a8aea331 100644 --- a/man/paho_dengue.Rd +++ b/man/paho_dengue.Rd @@ -21,7 +21,7 @@ the most recent issue is returned. Mutually exclusive with \code{issues}.} \code{\link{epidata_call}} } \description{ -API docs: https://cmu-delphi.github.io/delphi-epidata/api/paho_dengue.html +API docs: \url{https://cmu-delphi.github.io/delphi-epidata/api/paho_dengue.html} } \examples{ \dontrun{ diff --git a/man/parse_signal.Rd b/man/parse_signal.Rd index 5a874aae..47976dbc 100644 --- a/man/parse_signal.Rd +++ b/man/parse_signal.Rd @@ -31,3 +31,4 @@ an instance of epidata_call \description{ fetch covidcast data } +\keyword{internal} diff --git a/man/pvt_cdc.Rd b/man/pvt_cdc.Rd index ae8f6250..4ada67d2 100644 --- a/man/pvt_cdc.Rd +++ b/man/pvt_cdc.Rd @@ -17,7 +17,7 @@ pvt_cdc(auth, locations, epiweeks) \code{\link{epidata_call}} } \description{ -API docs: https://cmu-delphi.github.io/delphi-epidata/api/cdc.html +API docs: \url{https://cmu-delphi.github.io/delphi-epidata/api/cdc.html} } \examples{ \dontrun{ diff --git a/man/pvt_dengue_sensors.Rd b/man/pvt_dengue_sensors.Rd index 77dac45e..43bb2fe5 100644 --- a/man/pvt_dengue_sensors.Rd +++ b/man/pvt_dengue_sensors.Rd @@ -20,7 +20,7 @@ pvt_dengue_sensors(auth, names, locations, epiweeks) \code{\link{epidata_call}} } \description{ -API docs: https://cmu-delphi.github.io/delphi-epidata/api/dengue_sensors.html +API docs: \url{https://cmu-delphi.github.io/delphi-epidata/api/dengue_sensors.html} } \details{ TODO: what are valid locations and names? diff --git a/man/pvt_ght.Rd b/man/pvt_ght.Rd index 1c97a019..4ec8dc4e 100644 --- a/man/pvt_ght.Rd +++ b/man/pvt_ght.Rd @@ -19,7 +19,7 @@ pvt_ght(auth, locations, epiweeks, query) \code{\link{epidata_call}} } \description{ -API docs: https://cmu-delphi.github.io/delphi-epidata/api/ght.html +API docs: \url{https://cmu-delphi.github.io/delphi-epidata/api/ght.html} } \details{ TODO: find a non-trivial query diff --git a/man/pvt_meta_norostat.Rd b/man/pvt_meta_norostat.Rd index 8d935cca..1aee23aa 100644 --- a/man/pvt_meta_norostat.Rd +++ b/man/pvt_meta_norostat.Rd @@ -13,7 +13,7 @@ pvt_meta_norostat(auth) \code{\link{epidata_call}} } \description{ -API docs: https://cmu-delphi.github.io/delphi-epidata/api/meta_norostat.html +API docs: \url{https://cmu-delphi.github.io/delphi-epidata/api/meta_norostat.html} } \examples{ \dontrun{ diff --git a/man/pvt_norostat.Rd b/man/pvt_norostat.Rd index 6c305156..3a3e449b 100644 --- a/man/pvt_norostat.Rd +++ b/man/pvt_norostat.Rd @@ -17,7 +17,7 @@ pvt_norostat(auth, locations, epiweeks) \code{\link{epidata_call}} } \description{ -API docs: https://cmu-delphi.github.io/delphi-epidata/api/norostat.html +API docs: \url{https://cmu-delphi.github.io/delphi-epidata/api/norostat.html} } \examples{ \dontrun{ diff --git a/man/pvt_quidel.Rd b/man/pvt_quidel.Rd index 37fc65aa..5b16b060 100644 --- a/man/pvt_quidel.Rd +++ b/man/pvt_quidel.Rd @@ -17,7 +17,7 @@ pvt_quidel(auth, locations, epiweeks) \code{\link{epidata_call}} } \description{ -API docs: https://cmu-delphi.github.io/delphi-epidata/api/quidel.html +API docs: \url{https://cmu-delphi.github.io/delphi-epidata/api/quidel.html} } \examples{ \dontrun{ diff --git a/man/pvt_sensors.Rd b/man/pvt_sensors.Rd index ce4ad456..088eec11 100644 --- a/man/pvt_sensors.Rd +++ b/man/pvt_sensors.Rd @@ -19,7 +19,7 @@ pvt_sensors(auth, names, locations, epiweeks) \code{\link{epidata_call}} } \description{ -API docs: https://cmu-delphi.github.io/delphi-epidata/api/sensors.html +API docs: \url{https://cmu-delphi.github.io/delphi-epidata/api/sensors.html} } \examples{ \dontrun{ diff --git a/man/pvt_twitter.Rd b/man/pvt_twitter.Rd index 57449bc4..2953c0ff 100644 --- a/man/pvt_twitter.Rd +++ b/man/pvt_twitter.Rd @@ -20,7 +20,7 @@ pvt_twitter(auth, locations, dates = NULL, epiweeks = NULL) \code{\link{epidata_call}} } \description{ -API docs: https://cmu-delphi.github.io/delphi-epidata/api/twitter.html +API docs: \url{https://cmu-delphi.github.io/delphi-epidata/api/twitter.html} } \examples{ \dontrun{ diff --git a/man/request_impl.Rd b/man/request_impl.Rd index 559b2fc0..476c7ee2 100644 --- a/man/request_impl.Rd +++ b/man/request_impl.Rd @@ -11,3 +11,4 @@ request_impl(epidata_call, format_type, fields = NULL, timeout_seconds = 30) Makes a request to the API and returns the response, catching HTTP errors and forwarding the HTTP body in R errors } +\keyword{internal} diff --git a/man/timeset.Rd b/man/timeset.Rd index ccd3da86..91c005b5 100644 --- a/man/timeset.Rd +++ b/man/timeset.Rd @@ -4,22 +4,25 @@ \alias{timeset} \title{timeset} \description{ -A collection of date-like values, including dates, epiweeks, and ranges of -dates or epiweeks (\code{\link{epirange}}). This is often used to specify the time -dimension for an epidata query. The allowed values are: +Many API calls accept timesets to specify the time ranges of data being +requested. Timesets can be specified with \code{epirange()}, as \code{Date} objects, or +with wildcards. } \details{ +Timesets are not special R types; the term simply describes any value that +would be accepted by epidatr to specify the time value of an epidata query. +The allowed values are: \itemize{ \item Dates: \code{Date} instances, integer-like values, or integer-like strings that -take the form YYYYMMDD, -\item Epiweeks: integer-like values or integer-like strings that take the form -YYYYMM, -\item EpiRanges: a list of \code{\link{epirange}} instances. -\item Wildcard: "*" (requests all available values for this dimension) +take the form YYYYMMDD. +\item Epiweeks: Integer-like values or integer-like strings that take the form +YYYYWW. +\item EpiRanges: A range returned by \code{epirange()}, or a list of multiple ranges +\item Wildcard: The string \code{"*"}, which request all available time values } Please refer to the specific endpoint documentation for guidance on using dates vs weeks. Most endpoints support only one or the other. Some (less commonly used) endpoints may not accept the \code{"*"} wildcard, but this can be -simulated with a large \code{\link{epirange}}. +simulated with a large \code{epirange()}. } diff --git a/man/wiki.Rd b/man/wiki.Rd index 9cfc72de..42ef3a2c 100644 --- a/man/wiki.Rd +++ b/man/wiki.Rd @@ -22,7 +22,7 @@ wiki(articles, dates = NULL, epiweeks = NULL, hours = NULL, language = "en") \code{\link{epidata_call}} } \description{ -API docs: https://cmu-delphi.github.io/delphi-epidata/api/wiki.html +API docs: \url{https://cmu-delphi.github.io/delphi-epidata/api/wiki.html} } \examples{ \dontrun{ diff --git a/vignettes/development.rmd b/vignettes/development.rmd index 772c06ae..186f0795 100644 --- a/vignettes/development.rmd +++ b/vignettes/development.rmd @@ -2,7 +2,7 @@ title: "Notes for Developers" output: rmarkdown::html_vignette vignette: > - %\VignetteIndexEntry{Vignette Title} + %\VignetteIndexEntry{Notes for Developers} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- diff --git a/vignettes/epidatr.Rmd b/vignettes/epidatr.Rmd index 04da441d..ce8fbbb3 100644 --- a/vignettes/epidatr.Rmd +++ b/vignettes/epidatr.Rmd @@ -14,32 +14,81 @@ library(epidatr) library(dplyr) ``` +The epidatr package provides access to all the endpoints of the [Delphi Epidata +API](https://cmu-delphi.github.io/delphi-epidata/), and can be used to make +requests for specific signals on specific dates and in selected geographic +regions. + +We recommend you register for an API key. While most endpoints are available +without one, there are [limits on API usage for anonymous +users](https://cmu-delphi.github.io/delphi-epidata/api/api_keys.html), including +a rate limit. If you regularly request large amounts of data, please consider +[registering for an API +key](https://api.delphi.cmu.edu/epidata/admin/registration_form). You can then +specify this key by either + +- setting the environment variable `DELPHI_EPIDATA_KEY`, such as by editing your + `.Renviron` file +- setting the option `delphi.epidata.key` using `options()` + ## Basic Usage -Fetching some data from the Delphi Epidata API is simple. -First, we find the function for the endpoint we need, then we find the right arguments, and finally we `fetch` a tibble with the data. +Fetching some data from the Delphi Epidata API is simple. Suppose we are +interested in the [`covidcast` +endpoint](https://cmu-delphi.github.io/delphi-epidata/api/covidcast.html), which +provides access to a range of data on COVID-19. Reviewing the endpoint +documentation, we see that we need to specify a data source name, a signal name, +a geographic level, a time resolution, and the location and times of interest. + +In this case, the `covidcast()` function lets us specify these parameters for +the endpoint: + +```{r} +epicall <- covidcast( + "fb-survey", "smoothed_cli", "state", "day", "pa", + epirange(20210405, 20210410) +) +``` + +The `epicall` object is now an object representing the query we wish to make. +The `fetch()` function allows us to retrieve the results as a tibble: ```{r} -epicall <- covidcast("fb-survey", "smoothed_cli", "state", "day", "pa", epirange(20210405, 20210410)) epicall %>% fetch() ``` -The [Delphi Epidata API documentation](https://cmu-delphi.github.io/delphi-epidata/api/covidcast.html) has more information on the available endpoints and arguments. -Examples queries with all the endpoint functions available in this package are given below. +The [Delphi Epidata API documentation](https://cmu-delphi.github.io/delphi-epidata/) has more information on the available endpoints and arguments. +Examples queries with all the endpoint functions available in this package are given [below](#example-queries). ## Advanced Usage (Experimental) -You can use `covidcast_epidata` to get help with finding sources and functions without leaving R. -Using tab completion after typing `epidata$signals$` below, you can see all the available sources and signals in the API, with the format `source:signal`. -Note that some signal names have dashes in them, so to access them we rely on the backtick operator. +The [COVIDcast +endpoint](https://cmu-delphi.github.io/delphi-epidata/api/covidcast.html) of the +Epidata API contains many separate data sources and signals. It can be difficult +to find the name of the signal you're looking for, so you can use +`covidcast_epidata` to get help with finding sources and functions without +leaving R. + +The `covidcast_epidata()` function fetches a list of all signals, and returns an +object containing fields for every signal: ```{r} -epidata <- epidatr:::covidcast_epidata() +epidata <- covidcast_epidata() epidata$signals +``` + +If you use an editor that supports tab completion, such as RStudio, type +`epidata$signals$` and wait for the tab completion popup. You will be able to +type the name of signals and have the autocomplete feature select them from the +list for you. Note that some signal names have dashes in them, so to access them +we rely on the backtick operator: + +```{r} epidata$signals$`fb-survey:smoothed_cli` ``` -From there, you can construct a call analogous to the one above, but using the API object instead of the functions directly. +These objects can be used directly to fetch data, without requiring us to use +the `covidcast()` function. Simply use the `$call` attribute of the object: ```{r} epicall <- epidata$signals$`fb-survey:smoothed_cli`$call("state", "pa", epirange(20210405, 20210410))