Learn R Programming

Delphi Epidata R client

The Delphi Epidata API provides real-time access to epidemiological surveillance data for influenza, COVID-19, and other diseases from both official government sources such as the Centers for Disease Control and Prevention (CDC), private partners such as Facebook (now Meta) and Change Healthcare, and other public datasets like Google Trends. It is built and maintained by the Carnegie Mellon University Delphi Research Group.

This package is designed to streamline the downloading and usage of data from the Delphi Epidata API. It provides a simple R interface to the API, including functions for downloading data, parsing the results, and converting the data into a tidy format. The API stores a historical record of all data, including corrections and updates, which is particularly useful for accurately backtesting forecasting models. We also provide packages for downstream data processing (epiprocess) and modeling (epipredict).

Usage

library(epidatr)
# Obtain the smoothed covid-like illness (CLI) signal from Delphi's US COVID-19
# Trends and Impact Survey (CTIS), in partnership with Facebook, as it was on
# April 10, 2021 for the US at the national level
epidata <- pub_covidcast(
  source = "fb-survey",
  signals = "smoothed_cli",
  geo_type = "nation",
  time_type = "day",
  geo_values = "us",
  time_values = epirange(20210101, 20210601),
  as_of = 20210601
)
epidata
#> # A tibble: 151 × 15
#>    geo_value signal    source geo_type time_type time_value direction issue     
#>    <chr>     <chr>     <chr>  <fct>    <fct>     <date>         <dbl> <date>    
#>  1 us        smoothed… fb-su… nation   day       2021-01-01        NA 2021-01-06
#>  2 us        smoothed… fb-su… nation   day       2021-01-02        NA 2021-01-07
#>  3 us        smoothed… fb-su… nation   day       2021-01-03        NA 2021-01-08
#>  4 us        smoothed… fb-su… nation   day       2021-01-04        NA 2021-01-09
#>  5 us        smoothed… fb-su… nation   day       2021-01-05        NA 2021-01-10
#>  6 us        smoothed… fb-su… nation   day       2021-01-06        NA 2021-01-29
#>  7 us        smoothed… fb-su… nation   day       2021-01-07        NA 2021-01-29
#>  8 us        smoothed… fb-su… nation   day       2021-01-08        NA 2021-01-29
#>  9 us        smoothed… fb-su… nation   day       2021-01-09        NA 2021-01-29
#> 10 us        smoothed… fb-su… nation   day       2021-01-10        NA 2021-01-29
#> # ℹ 141 more rows
#> # ℹ 7 more variables: lag <dbl>, missing_value <dbl>, missing_stderr <dbl>,
#> #   missing_sample_size <dbl>, value <dbl>, stderr <dbl>, sample_size <dbl>

Installation

Installing the package is straightforward.

# Install the CRAN version
pak::pkg_install("epidatr")
# Install the development version from the GitHub dev branch
pak::pkg_install("cmu-delphi/epidatr@dev")

Our CRAN listing is here.

API Keys

The Delphi API requires a (free) API key for full functionality. To generate your key, register for a pseudo-anonymous account here and see more discussion on the general API website. The epidatr client will automatically look for this key in the environment variable DELPHI_EPIDATA_KEY. We recommend storing your key in your .Renviron file, which R will read by default.

Note that for the time being, the private endpoints (i.e. those prefixed with pvt) will require a separate key that needs to be passed as an argument.

For users of the covidcast R package

The covidcast package is deprecated and will no longer be updated. The epidatr package is a complete rewrite of the covidcast package, with a focus on speed, reliability, and ease of use. It also supports more endpoints and data sources than covidcast. When migrating from that package, you will need to use the pub_covidcast function in epidatr.

Get updates

You should consider subscribing to the API mailing list to be notified of package updates, new data sources, corrections, and other updates.

Usage terms and citation

We request that if you use the epidatr package in your work, or use any of the data provided by the Delphi Epidata API through non-covidcast endpoints, that you cite us using the citation given by citation("epidatr"). If you use any of the data from the covidcast endpoint, please use the COVIDcast citation as well. See the COVIDcast licensing documentation and the licensing documentation for other endpoints for information about citing the datasets provided by the API.

Warning: If you use data from the Epidata API to power a product, dashboard, app, or other service, please download the data you need and store it centrally rather than making API requests for every user. Our server resources are limited and cannot support high-volume interactive use.

See also the Terms of Use, noting that the data is a research product and not warranted for a particular purpose.

Copy Link

Version

Install

install.packages('epidatr')

Monthly Downloads

662

Version

1.2.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

David Weber

Last Published

June 20th, 2024

Functions in epidatr (1.2.0)

avail_endpoints

List all available Epidata API endpoints
pub_covid_hosp_facility

COVID hospitalizations by facility
pub_covid_hosp_facility_lookup

Helper for finding COVID hospitalization facilities
disable_cache

Turn off the caching for this session
cache_epidata_call

Dispatch caching
pvt_ght

Google Health Trends health topics search volume
with_base_url

epidata_call object using a different base URL
request_impl

Makes a request to the API and returns the response, catching HTTP errors and forwarding the HTTP body in R errors
request_url

Returns the full request url for the given epidata_call
pvt_meta_norostat

Metadata for the NoroSTAT endpoint
do_request

performs the request
timeset

Timeset formats for specifying dates
set_cache

Create or renew a cache for this session
pub_flusurv

CDC FluSurv flu hospitalizations
pub_fluview

CDC FluView ILINet outpatient doctor visits
cache_info

Describe current cache
epirange

Specify a range of days or weeks for API requests
check_is_cachable

helper that checks whether a call is actually cachable
fetch_args_list

Set custom API request parameters
get_wildcard_equivalent_dates

helper to convert a date wildcard ("*") to an appropriate epirange
get_api_key

Get and set API keys
pub_fluview_clinical

CDC FluView flu tests from clinical labs
pub_fluview_meta

Metadata for the FluView endpoint
pub_nidss_dengue

NIDSS dengue cases (Taiwan)
pub_meta

Metadata for the Delphi Epidata API
date_to_epiweek

Converts a date (integer or character) to an epiweek
covidcast_epidata

Creates the COVIDcast Epidata autocomplete helper
pub_covid_hosp_state_timeseries

COVID hospitalizations by state
assert_character_param

Allows character vectors
assert_date_param

Allows a vector of date_like params: date, character, or integer-like
pub_covidcast

Various COVID and flu signals via the COVIDcast endpoint
pub_dengue_nowcast

Delphi's PAHO dengue nowcasts (North and South America)
pub_ecdc_ili

ECDC ILI incidence (Europe)
assert_integerish_param

Allows integer-like vectors
pvt_cdc

CDC total and by topic webpage visits
fetch_classic

Fetches the data, raises on epidata errors, and returns the results as a JSON-like list
fetch_tbl

Fetches the data and returns a tibble
format_item

Helper function to cast values, non-list vectors, and/or EpiRanges to strings
assert_timeset_param

Allows a timeset param: a date vector, a character vector, an integer-like vector, or a single EpiRange
pvt_dengue_sensors

PAHO dengue digital surveillance sensors (North and South America)
pvt_twitter

HealthTweets total and influenza-related tweets
pvt_sensors

Influenza and dengue digital surveillance sensors
check_is_recent

helper that checks whether a call is a somewhat dangerous cache
clear_cache

Manually reset the cache, deleting all currently saved data and starting afresh
create_epidata_call

An abstraction that holds information needed to make an epidata request
pub_covidcast_meta

Metadata for the COVIDcast endpoint
parse_api_week

parse_api_week converts an integer to a date
epidatr-package

epidatr: Client for Delphi's 'Epidata' API
parse_signal

turn a signal into a callable
format_list

Helper function to build a list of values and/or ranges
pub_gft

Google Flu Trends flu search volume
pub_delphi

Delphi's ILINet outpatient doctor visits forecasts
pub_paho_dengue

PAHO dengue data (North and South America)
pub_wiki

Wikipedia webpage counts by article
reformat_epirange

helper to convert an epirange from week to day or vice versa
release_bullets

inserts each string as a bullet at the end of the "Prepare for release" section
pvt_quidel

Quidel COVID-19 and influenza testing data
pub_kcdc_ili

KCDC ILI incidence (Korea)
pub_nidss_flu

NIDSS flu doctor visits (Taiwan)
pub_nowcast

Delphi's ILI Nearby nowcasts
pvt_norostat

CDC NoroSTAT norovirus outbreaks