Giter Club home page Giter Club logo

coronavirus-dashboard-api-r-sdk's Introduction

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

Software Development Kit (SDK) for R

This is an R SDK for the COVID-19 API, as published by Public Health England on Coronavirus (COVID-19) in the UK. The source code of this library is housed on GitHub.

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

The SDK is also available for Python and JavaScript.

Installation

You can install the released version of ukcovid19 from CRAN with:

install.packages("ukcovid19")

or install from GitHub as follows:

remotes::install_github("publichealthengland/coronavirus-dashboard-api-R-sdk")

Pagination

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

To use the library, run:

library(ukcovid19)

or simply prepend the function names with ukcovid19; for instance:

ukcovid19::get_options()

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 filters parameter:

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

Next step is to construct the value of the 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:

  • newCasesByPublishDate: New cases (by publish date)
  • cumCasesByPublishDate: Cumulative cases (by publish date)
  • newDeathsByDeathDate: New deaths (by death date)
  • cumDeathsByDeathDate: Cumulative deaths (by death date)

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 filters and structure to get the data from the API:

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

# Showing the head:
print(head(data))
        date areaName  areaCode newCasesByPublishDate cumCasesByPublishDate newDeaths28DaysByPublishDate cumDeaths28DaysByPublishDate
1 2020-08-19  England E92000001                   707                277516                           15                        36757
2 2020-08-18  England E92000001                   975                276809                           11                        36742
3 2020-08-17  England E92000001                   634                275834                            3                        36731
4 2020-08-16  England E92000001                   952                275200                            3                        36728
5 2020-08-15  England E92000001                   934                274248                            2                        36725
6 2020-08-14  England E92000001                  1284                273314                           10                        36723

To see the timestamp for the last update, run:

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

print(timestamp)
[1] "2020-08-02 14:50:59 GMT"

To get the latest data by a specific metric, use the 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)
        date areaName  areaCode newCasesByPublishDate cumCasesByPublishDate  newDeathsByDeathDate cumDeathsByDeathDate
1 2020-08-02  England E92000001                   676                262746                    NA                   NA
2 2020-08-02 Scotland S92000003                    31                 18676                    NA                   NA
3 2020-08-02    Wales W92000004                    37                 17315                    NA                   NA

Developed and maintained by Public Health England.

Copyright (c) 2020, Public Health England.

coronavirus-dashboard-api-r-sdk's People

Contributors

xenatisch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coronavirus-dashboard-api-r-sdk's Issues

CRAN release

This overlaps with #2. Is there still going to be a CRAN release for this package?

Problems with remote install on rocker image / not on CRAN

Despite README saying this is on CRAN, I cannot find it. Are there plans to submit it as having terrible problems trying to remote install on a rocker pipeeline image on GitLab.

I have been able to install the API and sucessfully use it on my local machine with no problem. However, when I try to install it on the rocker image I get the following message:

> remotes::install_github("publichealthengland/coronavirus-dashboard-api-R-sdk")
Using bundled GitHub PAT. Please add your own PAT to the env var `GITHUB_PAT`
Error: Failed to install 'unknown package' from GitHub:
  cannot open URL 'https://api.github.com/repos/publichealthengland/coronavirus-dashboard-api-R-sdk/contents/DESCRIPTION?ref=HEAD'
Execution halted
Cleaning up project directory and file based variables 00:01
ERROR: Job failed: exit code 1

Clicking on the URL it is attempting to open gives the following error:

{
  "message": "No commit found for the ref HEAD'",
  "documentation_url": "https://docs.github.com/v3/repos/contents/"
}

The only thread I have found about this error is on github suggesting it may be because default branch is not called master but as far as I can tell it is called master. r-lib/remotes#508

Not too sure how to problem solve this further so any pointers or a look into why it is isn't working would be very welcome.

Package install instructions.

README indicates that the package is on CRAN but I think this is not actually the case yet? I assume this is in the pipeline but it might be a good idea to amend to the README until this is the case.

404 error

Hi,

Thanks for building out this interface - great work.

When running the examples in the README I see the following:

Error in get_request(filters, structure, page = current_page) : 
  Client errorNot FoundClient error: (404) Not Found

when running any get_data call. My colleague @kathsherratt has been able to replicate this issue and we have seen it across Mac, Linux, and Windows.

We have been looking at supporting this data in our covidregionaldata aggregation package (https://cran.r-project.org/web/packages/covidregionaldata/index.html) but also haven't had any luck accessing the data when using the internal package code.

Any ideas?

It would be really great to have access to this data for our Rt estimation efforts (https://github.com/epiforecasts/covid-rt-estimates) and other research.

Access to Northern Ireland data

Hello, thank you for putting online this great API.
I am using R4.0.2 on Windows 10.
When I try to access the Northern Ireland data using area name "northern ireland" or area code "N92000002", the retrieved content is empty. It works well for the 3 other nations though.

Wrong API link

Hi Team,

This app unfotunately no longer works - I think this is because the API link has changed, should be a simple fix?

Sam

MSOA queries

I am trying to extract MSOA data using the api. As a trial I have used data I downloaded using the download data page https://coronavirus.data.gov.uk/details/download . For the puposes of the experiment I am trying to download data for Barnet council, at msoa level, for the variable newCasesBySpecimenDateRollingRate, as a csv file. When using the tool I get the following link which successfully downloads.

However, when I try and use the API query I get the error message "Error in curl::curl_fetch_memory(url, handle = handle) :
Timeout was reached: [api.coronavirus.data.gov.uk] Operation timed out after 10001 milliseconds with 0 bytes received" I have got this message for a wide range of different msoa options


query_filters <- c(
      'areaType=msoa',
"areaCode=E09000003"
)

cases_and_deaths = list(
  date = "date",
  areaName = "areaName",
  areaType = "areaType",
  areaCode = "areaCode",
  newCasesByPublishDate = "newCasesBySpecimenDateRollingRate"
)


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

changing the area type to utla or ltla does not result in an error. Does the api work for msoa? choosing options form the recently added vaccination data also produces an error, https://coronavirus.data.gov.uk/details/whats-new even though this data is definately provided in msoa format.

Any help or clarification would be appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.