Package 'onsr'

Title: Client for the 'ONS' API
Description: Client for the 'Office of National Statistics' ('ONS') API <https://api.beta.ons.gov.uk/v1>.
Authors: Kostas Vasilopoulos [aut, cre]
Maintainer: Kostas Vasilopoulos <[email protected]>
License: GPL (>= 3)
Version: 1.0.2
Built: 2025-01-13 02:46:46 UTC
Source: https://github.com/kvasilopoulos/onsr

Help Index


Quickly browse to ONS' developer webpage

Description

This function take you to the ONS' developer webpage.

Usage

ons_browse()

Value

An atomic character vector with the url of the webpage

Examples

ons_browse()

Quickly browse to dataset's Quality and Methodology Information (QMI)

Description

This function take you to the QMI.

Usage

ons_browse_qmi(id = NULL)

Arguments

id

⁠[character]⁠ Id that represents a dataset.

Value

An atomic character vector url with of the webpage

Examples

ons_browse_qmi("cpih01")

Explore codes and lists

Description

Used to get details about codes and code lists stored by ONS. Codes are used to provide a common definition when presenting statistics with related categories. Codes are gathered in code lists, which may change over time to include new or different codes. The meaning of a code should not change over time, but new codes may be created where new meaning is required.

Usage

ons_codelists()

ons_codelist(code_id = NULL)

ons_codelist_editions(code_id = NULL)

ons_codelist_edition(code_id = NULL, edition = NULL)

Arguments

code_id

⁠[character]⁠. The id of a codelist.

edition

⁠[character]⁠ A subset of the dataset representing a specific time period. For some datasets this edition can contain all time periods (all historical data). The latest version of this is displayed by default.

Value

A list or character vector.

Examples

ons_codelists()
ons_codelist(code_id = "quarter")

#editions
ons_codelist_editions(code_id = "quarter")
ons_codelist_edition(code_id = "quarter", edition = "one-off")

Explore codes and lists

Description

Used to get details about codes and code lists stored by ONS. Codes are used to provide a common definition when presenting statistics with related categories. Codes are gathered in code lists, which may change over time to include new or different codes. The meaning of a code should not change over time, but new codes may be created where new meaning is required.

Usage

ons_codes(code_id = NULL, edition = NULL)

ons_code(code_id = NULL, edition = NULL, code = NULL)

ons_code_dataset(code_id = NULL, edition = NULL, code = NULL)

Arguments

code_id

⁠[character]⁠. The id of a codelist.

edition

⁠[character]⁠ A subset of the dataset representing a specific time period. For some datasets this edition can contain all time periods (all historical data). The latest version of this is displayed by default.

code

⁠[character]⁠ The ID of the code within a code list.

Value

A list or character vector.

Examples

#codes
ons_codes(code_id = "quarter", edition = "one-off")
ons_code(code_id = "quarter", edition = "one-off", code = "q2")

ons_code_dataset(code_id = "quarter", edition = "one-off", code = "q2")

ONS Datasets

Description

A grouping of data (editions) with shared dimensions, for example Sex, Age and Geography, and all published history of this group of data. The options in these dimensions can change over time leading to separate editions. For example: Population Estimates for UK, England and Wales, Scotland and Northern Ireland.

Usage

ons_datasets()

ons_ids()

Value

A tibble with the datasets.

Examples

# Find all the information about the data
ons_datasets()

# Just the ids
ons_ids()

Description of the Dataset

Description

This function provides a description of the important information about a dataset.

Usage

ons_desc(id = NULL)

Arguments

id

⁠[character]⁠ Id that represents a dataset.

Value

A description of the requested dataset.

See Also

ons_meta()

Examples

ons_desc("cpih01")

Access dataset's additional information

Description

Data in each version is broken down by dimensions, and a unique combination of dimension options in a version can be used to retrieve observation level data.

Usage

ons_dim(id = NULL, edition = NULL, version = NULL)

ons_dim_opts(
  id = NULL,
  edition = NULL,
  version = NULL,
  dimension = NULL,
  limit = NULL,
  offset = NULL
)

ons_meta(id = NULL, edition = NULL, version = NULL)

Arguments

id

⁠[character]⁠ Id that represents a dataset.

edition

⁠[character]⁠ A subset of the dataset representing a specific time period. For some datasets this edition can contain all time periods (all historical data). The latest version of this is displayed by default.

version

⁠[character]⁠ A specific instance of the edition at a point in time. New versions can be published as a result of corrections, revisions or new data becoming available.

dimension

⁠[character]⁠

limit

⁠[numeric(1): NULL]⁠ Number of records to return. By default is NULL, which means that the defaults of the ONS API are used. You can set it to a number to request more (or less) records, and also to Inf to request all records.

offset

⁠[numeric(1): NULL]⁠ The position in the dataset of a particular record. By specifying offset , you retrieve a subset of records starting with the offset value. Offset normally works with length , which determines how many records to retrieve starting from the offset.

Value

A character vector.

Examples

## Not run: 
ons_dim(id = "cpih01")

ons_dim_opts(id = "cpih01", dimension = "time")

ons_meta(id = "cpih01")

## End(Not run)

Download data from ONS

Description

This functions is used to find information about data published by the ONS. Datasets are published in unique versions, which are categorized by edition. Available datasets are given an id. All available id can be viewed with ons_ids().

Usage

ons_get(
  id = NULL,
  edition = NULL,
  version = NULL,
  ons_read = getOption("onsr.read"),
  ...
)

ons_get_obs(id = NULL, edition = NULL, version = NULL, ...)

Arguments

id

⁠[character]⁠ Id that represents a dataset.

edition

⁠[character]⁠ A subset of the dataset representing a specific time period. For some datasets this edition can contain all time periods (all historical data). The latest version of this is displayed by default.

version

⁠[character]⁠ A specific instance of the edition at a point in time. New versions can be published as a result of corrections, revisions or new data becoming available.

ons_read

⁠[character]⁠. Reading backend, one of readr, data.table or vroom.

...

Further arguments passed on the methods.

Value

A tibble with the dataset in tidy format.

Examples

ons_get(id = "cpih01")

# Same dataset but older version
ons_get(id = "cpih01", version = "5")


# Take only specific observations
ons_get_obs("cpih01", geography = "K02000001", aggregate = "cpih1dim1A0", time = "Oct-11")

# Or can use a wildcard for the time
ons_get_obs("cpih01", geography = "K02000001", aggregate = "cpih1dim1A0", time = "*")

Latest info on ONS Datasets

Description

This functions are used to access the latest href, version and edition of a dataset.

Usage

ons_latest_href(id = NULL)

ons_latest_version(id = NULL)

ons_latest_edition(id = NULL)

Arguments

id

⁠[character]⁠ Id that represents a dataset.

Value

An atomic character vector with the latest info.

Examples

ons_latest_href("cpih01")
ons_latest_version("cpih01")
ons_latest_edition("cpih01")