knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(ukcovid19)

Coronavirus (COVID-19) in the UK - API Service

Software Development Kit (SDK)

This is an R SDK for the COVID-19 API, as published by Public Health England on \href{Coronavirus (COVID-19) in the UK}{https://api.coronavirus.data.gov.uk/}. The source code of this library is housed on \href{GitHub}{https://github.com/publichealthengland/coronavirus-dashboard-api-r-sdk}.

The API supplies the latest data for the COVID-19 outbreak in the United Kingdom.

The endpoint for the data provided using this SDK is:

https://api.coronavirus.data.gov.uk/v1/data

Pagination

Using this SDK will bypass the pagination process. You will always download the entire dataset unless the \code{latest_by} argument is defined.

Examples

We would like to extract the number of new cases, cumulative cases, new deaths and cumulative deaths for England using the API.

We start off by constructing the value of the \code{filters} parameter:

query_filters <- c(
    'areaType=nation',
    'areaName=England'
)

Next step is to construct the value of the \code{structure} parameter. To do so, we need to find out the name of the metric in which we are interested. You can find this information in the Developer's Guide on the Coronavirus Dashboard website.

In the case of this example, the metrics are as follows:

In its simplest form, we construct the structure as follows:

cases_and_deaths = list(
    date = "date",
    areaName = "areaName",
    areaCode = "areaCode",
    newCasesByPublishDate = "newCasesByPublishDate",
    cumCasesByPublishDate = "cumCasesByPublishDate",
    newDeaths28DaysByPublishDate = "newDeaths28DaysByPublishDate",
    cumDeaths28DaysByPublishDate = "cumDeaths28DaysByPublishDate"
)

Now, we can use \code{filters} and \code{structure} to get the data from the API:

data <- ukcovid19::get_data(
    filters = query_filters, 
    structure = cases_and_deaths
)

# Showing the head:
print(head(data))

To see the timestamp for the last update, run:

timestamp <- ukcovid19::last_update(
    filters = query_filters, 
    structure = cases_and_deaths
)

print(timestamp)

To get the latest data by a specific metric, use the \code{latest_by} argument as follows:

all_nations = c(
    "areaType=nation"
)

data <- get_data(
    filters = all_nations, 
    structure = cases_and_deaths,
    latest_by = "newCasesByPublishDate"
)

print(data)

Developed and maintained by \href{Public Health England}{http://coronavirus.data.gov.uk/}.

Copyright (c) 2020, Public Health England.



publichealthengland/coronavirus-dashboard-api-R-sdk documentation built on Aug. 26, 2020, 9:40 a.m.