Skip to contents

Extracts daily COVID-19 data for the UK, stratified by region and nation. Additional options for this class are: to return subnational English regions using NHS region boundaries instead of PHE boundaries (nhsregions = TRUE), a release date to download from (release_date) and a geographical resolution (resolution).

Super class

covidregionaldata::DataClass -> UK

Public fields

origin

name of origin to fetch data for

supported_levels

A list of supported levels.

supported_region_names

A list of region names in order of level.

supported_region_codes

A list of region codes in order of level.

common_data_urls

List of named links to raw data. The first, and only entry, is be named main.

level_data_urls

List of named links to raw data that are level specific.

source_data_cols

existing columns within the raw data

source_text

Plain text description of the source of the data

source_url

Website address for explanation/introduction of the data

query_filters

Set what filters to use to query the data

nhsregions

Whether to include NHS regions in the data

release_date

The release date for the data

resolution

The resolution of the data to return

authority_data

The raw data for creating authority lookup tables

Methods

Inherited methods


Method set_region_codes()

Specific function for getting region codes for UK .

Usage

UK$set_region_codes()


Method download()

UK specific download() function.

Usage

UK$download()


Method clean_level_1()

Region Level Data Cleaning

Usage

UK$clean_level_1()


Method clean_level_2()

Level 2 Data Cleaning

Usage

UK$clean_level_2()


Method new()

Initalize the UK Class

Usage

UK$new(nhsregions = FALSE, release_date = NULL, resolution = "utla", ...)

Arguments

nhsregions

Return subnational English regions using NHS region boundaries instead of PHE boundaries.

release_date

Date data was released. Default is to extract latest release. Dates should be in the format "yyyy-mm-dd".

resolution

"utla" (default) or "ltla", depending on which geographical resolution is preferred

...

Optional arguments passed to DataClass() initalize.

Examples

\dontrun{
UK$new(
 level = 1, localise = TRUE,
 verbose = True, steps = FALSE,
 nhsregions = FALSE, release_date = NULL,
 resolution = "utla"
)
}


Method download_filter()

Helper function for downloading data API

Usage

UK$download_filter(filter)

Arguments

filter

region filters


Method set_filters()

Set filters for UK data api query.

Usage

UK$set_filters()


Method download_nhs_regions()

Download NHS data for level 1 regions Separate NHS data is available for "first" admissions, excluding readmissions. This is available for England + English regions only. Data are available separately for the periods 2020-08-01 to 2021-04-06, and 2021-04-07 - present. See: https://www.england.nhs.uk/statistics/statistical-work-areas/covid-19-hospital-activity/ Section 2, "2. Estimated new hospital cases"

Usage

UK$download_nhs_regions()

Returns

nhs data.frame of nhs regions


Method add_nhs_regions()

Add NHS data for level 1 regions Separate NHS data is available for "first" admissions, excluding readmissions. This is available for England + English regions only. See: https://www.england.nhs.uk/statistics/statistical-work-areas/covid-19-hospital-activity/ Section 2, "2. Estimated new hospital cases"

Usage

UK$add_nhs_regions(clean_data, nhs_data)

Arguments

clean_data

Cleaned UK covid-19 data

nhs_data

NHS region data


Method specific_tests()

Specific tests for UK data. In addition to generic tests ran by DataClass$test() data for NHS regions are downloaded and ran through the same generic checks (test_cleaning, test_processing, test_return). If download = TRUE or a snapshot file is not found, the nhs data is downloaded and saved to the snapshot location provided. If an existing snapshot file is found then this data is used in the next tests. Tests data can be downloaded, cleaned, processed and returned. Designed to be ran from test and not ran directly.

Usage

UK$specific_tests(
  self_copy,
  download = FALSE,
  all = FALSE,
  snapshot_path = "",
  ...
)

Arguments

self_copy

R6class the object to test.

download

logical. To download the data (TRUE) or use a snapshot (FALSE). Defaults to FALSE.

all

logical. Run tests with all settings (TRUE) or with those defined in the current class instance (FALSE). Defaults to FALSE.

snapshot_path

character_array the path to save the downloaded snapshot to. Works on the snapshot path constructed by test but adds

...

Additional parameters to pass to specific_tests


Method clone()

The objects of this class are cloneable with this method.

Usage

UK$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

if (FALSE) {
# setup a data cache
start_using_memoise()

# download, clean and process level 1 UK data with hospital admissions
region <- UK$new(level = "1", nhsregions = TRUE)
region$return()

# initialise level 2 data
utla <- UK$new(level = "2")

# download UTLA data
utla$download()

# clean UTLA data
utla$clean()

# inspect available level 1 regions
utla$available_regions(level = "1")

# filter data to the East of England
utla$filter("East of England")

# process UTLA data
utla$process()

# return processed and filtered data
utla$return()

# inspect all data steps
utla$data
}

## ------------------------------------------------
## Method `UK$new`
## ------------------------------------------------

if (FALSE) {
UK$new(
 level = 1, localise = TRUE,
 verbose = True, steps = FALSE,
 nhsregions = FALSE, release_date = NULL,
 resolution = "utla"
)
}