| Title: | Download Data from the 'Office for National Statistics' |
|---|---|
| Description: | Provides functions to download and tidy statistical data published by the 'Office for National Statistics' <https://www.ons.gov.uk>. Covers GDP, inflation (CPI, CPIH, RPI), unemployment, employment, wages, trade, retail sales, house prices, productivity, population, and public sector finances. Most series are fetched from the 'ONS' website using its CSV time series endpoint. House price data is sourced from 'HM Land Registry' <https://www.gov.uk/government/organisations/land-registry>. Data is cached locally between sessions. |
| Authors: | Charles Coverdale [aut, cre] |
| Maintainer: | Charles Coverdale <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.4 |
| Built: | 2026-06-03 06:42:02 UTC |
| Source: | https://github.com/charlescoverdale/ons |
Provides functions to download and tidy statistical data published by the 'Office for National Statistics' https://www.ons.gov.uk. Covers GDP, inflation (CPI, CPIH, RPI), unemployment, employment, wages, trade, retail sales, house prices, productivity, population, and public sector finances. Most series are fetched from the 'ONS' website using its CSV time series endpoint. House price data is sourced from 'HM Land Registry' https://www.gov.uk/government/organisations/land-registry. Data is cached locally between sessions.
Maintainer: Charles Coverdale [email protected]
Useful links:
Report bugs at https://github.com/charlescoverdale/ons/issues
Removes cached data files stored by this package. By default all cached
files are deleted. Use max_age_days to remove only files older than a
given number of days.
clear_cache(max_age_days = NULL)clear_cache(max_age_days = NULL)
max_age_days |
Numeric. If supplied, only files older than this many
days are removed. If |
Invisibly returns NULL. Called for its side effect of deleting
cached files.
Other data access:
ons_get(),
ons_search()
op <- options(ons.cache_dir = tempdir()) clear_cache() options(op)op <- options(ons.cache_dir = tempdir()) clear_cache() options(op)
Downloads CPI, CPIH, or RPI data from the ONS. Returns either the annual rate of change or the index level.
ons_cpi( measure = c("cpi", "cpih", "rpi"), type = c("rate", "index"), from = NULL, to = NULL, cache = TRUE )ons_cpi( measure = c("cpi", "cpih", "rpi"), type = c("rate", "index"), from = NULL, to = NULL, cache = TRUE )
measure |
Character. One of |
type |
Character. One of |
from |
Date or character (YYYY-MM-DD). Start date. Defaults to
|
to |
Date or character (YYYY-MM-DD). End date. Defaults to |
cache |
Logical. Use cached data if available (default |
A data frame with columns:
Date. First day of the month.
Numeric. Inflation rate (percent) or index level.
Other economic indicators:
ons_gdp(),
ons_monthly_gdp(),
ons_population(),
ons_productivity()
op <- options(ons.cache_dir = tempdir()) try(ons_cpi(from = "2020-01-01")) options(op)op <- options(ons.cache_dir = tempdir()) try(ons_cpi(from = "2020-01-01")) options(op)
Downloads the UK employment rate (aged 16 to 64, seasonally adjusted) from the ONS Labour Market Statistics. Available from 1971.
ons_employment( group = c("total", "male", "female"), from = NULL, to = NULL, cache = TRUE )ons_employment( group = c("total", "male", "female"), from = NULL, to = NULL, cache = TRUE )
group |
Character. One of |
from |
Date or character (YYYY-MM-DD). Start date. Defaults to
|
to |
Date or character (YYYY-MM-DD). End date. Defaults to |
cache |
Logical. Use cached data if available (default |
A data frame with columns:
Date. First day of the period.
Numeric. Employment rate (percent).
Other labour market:
ons_inactivity(),
ons_unemployment(),
ons_wages()
op <- options(ons.cache_dir = tempdir()) try(ons_employment(from = "2020-01-01")) options(op)op <- options(ons.cache_dir = tempdir()) try(ons_employment(from = "2020-01-01")) options(op)
Downloads quarterly Gross Domestic Product data from the ONS. Available from 1948 (levels) or 1955 (growth rates).
ons_gdp( measure = c("growth", "yoy", "level", "nominal"), from = NULL, to = NULL, cache = TRUE )ons_gdp( measure = c("growth", "yoy", "level", "nominal"), from = NULL, to = NULL, cache = TRUE )
measure |
Character. One of |
from |
Date or character (YYYY-MM-DD). Start date. Defaults to
|
to |
Date or character (YYYY-MM-DD). End date. Defaults to |
cache |
Logical. Use cached data if available (default |
A data frame with columns:
Date. First day of the quarter.
Numeric. GDP value (percent for growth measures, GBP millions for level measures).
Other economic indicators:
ons_cpi(),
ons_monthly_gdp(),
ons_population(),
ons_productivity()
op <- options(ons.cache_dir = tempdir()) try(ons_gdp(from = "2020-01-01")) options(op)op <- options(ons.cache_dir = tempdir()) try(ons_gdp(from = "2020-01-01")) options(op)
Fetches a time series from the ONS website using its CDID (four-character series identifier). The function uses the ONS Search API to discover the download path, then retrieves the CSV.
ons_get(cdid, from = NULL, to = NULL, cache = TRUE)ons_get(cdid, from = NULL, to = NULL, cache = TRUE)
cdid |
Character vector. One or more ONS CDID codes (e.g. |
from |
Date or character (YYYY-MM-DD). Start date filter. Defaults to
|
to |
Date or character (YYYY-MM-DD). End date filter. Defaults to
|
cache |
Logical. Use cached data if available (default |
CDID codes can be found by browsing the ONS time series explorer at
https://www.ons.gov.uk/timeseriestool or by using ons_search().
A data frame with columns:
Date. Observation date (first day of the period).
Character. The CDID code.
Numeric. Observation value.
Other data access:
clear_cache(),
ons_search()
op <- options(ons.cache_dir = tempdir()) try(ons_get("IHYQ", from = "2020-01-01")) options(op)op <- options(ons.cache_dir = tempdir()) try(ons_get("IHYQ", from = "2020-01-01")) options(op)
Downloads UK average house prices from the HM Land Registry UK House Price Index. Available from 1968. Data is jointly produced by the ONS and HM Land Registry.
ons_house_prices(from = NULL, to = NULL, cache = TRUE)ons_house_prices(from = NULL, to = NULL, cache = TRUE)
from |
Date or character (YYYY-MM-DD). Start date. Defaults to
|
to |
Date or character (YYYY-MM-DD). End date. Defaults to |
cache |
Logical. Use cached data if available (default |
The function automatically finds the latest available monthly file from HM Land Registry, working backwards from the current month.
A data frame with columns:
Date. First day of the month.
Numeric. Average house price (GBP).
Numeric. Annual percentage change.
https://www.gov.uk/government/collections/uk-house-price-index-reports
Other trade and prices:
ons_retail_sales(),
ons_trade()
op <- options(ons.cache_dir = tempdir()) try(ons_house_prices(from = "2020-01-01")) options(op)op <- options(ons.cache_dir = tempdir()) try(ons_house_prices(from = "2020-01-01")) options(op)
Downloads the number of economically inactive people (aged 16 to 64, seasonally adjusted) from the ONS Labour Market Statistics. Available from 1971.
ons_inactivity(from = NULL, to = NULL, cache = TRUE)ons_inactivity(from = NULL, to = NULL, cache = TRUE)
from |
Date or character (YYYY-MM-DD). Start date. Defaults to
|
to |
Date or character (YYYY-MM-DD). End date. Defaults to |
cache |
Logical. Use cached data if available (default |
A data frame with columns:
Date. First day of the period.
Numeric. Economically inactive people (thousands).
Other labour market:
ons_employment(),
ons_unemployment(),
ons_wages()
op <- options(ons.cache_dir = tempdir()) try(ons_inactivity(from = "2020-01-01")) options(op)op <- options(ons.cache_dir = tempdir()) try(ons_inactivity(from = "2020-01-01")) options(op)
Downloads the monthly estimate of GDP from the ONS. This is an experimental index-based estimate, available from 1997.
ons_monthly_gdp(from = NULL, to = NULL, cache = TRUE)ons_monthly_gdp(from = NULL, to = NULL, cache = TRUE)
from |
Date or character (YYYY-MM-DD). Start date. Defaults to
|
to |
Date or character (YYYY-MM-DD). End date. Defaults to |
cache |
Logical. Use cached data if available (default |
A data frame with columns:
Date. First day of the month.
Numeric. Monthly GDP index (2019 = 100).
Other economic indicators:
ons_cpi(),
ons_gdp(),
ons_population(),
ons_productivity()
op <- options(ons.cache_dir = tempdir()) try(ons_monthly_gdp(from = "2020-01-01")) options(op)op <- options(ons.cache_dir = tempdir()) try(ons_monthly_gdp(from = "2020-01-01")) options(op)
Downloads mid-year population estimates for the United Kingdom from the ONS. Returns annual estimates.
ons_population(from = NULL, to = NULL, cache = TRUE)ons_population(from = NULL, to = NULL, cache = TRUE)
from |
Date or character (YYYY-MM-DD). Start date. Defaults to
|
to |
Date or character (YYYY-MM-DD). End date. Defaults to |
cache |
Logical. Use cached data if available (default |
A data frame with columns:
Date. Mid-year date (represented as 1 January).
Numeric. Population estimate (thousands).
Other economic indicators:
ons_cpi(),
ons_gdp(),
ons_monthly_gdp(),
ons_productivity()
op <- options(ons.cache_dir = tempdir()) try(ons_population(from = "2000-01-01")) options(op)op <- options(ons.cache_dir = tempdir()) try(ons_population(from = "2000-01-01")) options(op)
Downloads quarterly labour productivity data from the ONS. Available as output per hour worked or output per worker.
ons_productivity( measure = c("per_hour", "per_worker"), from = NULL, to = NULL, cache = TRUE )ons_productivity( measure = c("per_hour", "per_worker"), from = NULL, to = NULL, cache = TRUE )
measure |
Character. One of |
from |
Date or character (YYYY-MM-DD). Start date. Defaults to
|
to |
Date or character (YYYY-MM-DD). End date. Defaults to |
cache |
Logical. Use cached data if available (default |
A data frame with columns:
Date. First day of the quarter.
Numeric. Productivity index.
Other economic indicators:
ons_cpi(),
ons_gdp(),
ons_monthly_gdp(),
ons_population()
op <- options(ons.cache_dir = tempdir()) try(ons_productivity(from = "2020-01-01")) options(op)op <- options(ons.cache_dir = tempdir()) try(ons_productivity(from = "2020-01-01")) options(op)
Downloads public sector net borrowing (excluding public sector banks) from the ONS. Available from 1993.
ons_public_finances(from = NULL, to = NULL, cache = TRUE)ons_public_finances(from = NULL, to = NULL, cache = TRUE)
from |
Date or character (YYYY-MM-DD). Start date. Defaults to
|
to |
Date or character (YYYY-MM-DD). End date. Defaults to |
cache |
Logical. Use cached data if available (default |
A data frame with columns:
Date. First day of the month.
Numeric. Public sector net borrowing (GBP millions).
op <- options(ons.cache_dir = tempdir()) try(ons_public_finances(from = "2020-01-01")) options(op)op <- options(ons.cache_dir = tempdir()) try(ons_public_finances(from = "2020-01-01")) options(op)
Downloads the Retail Sales Index from the ONS. Returns volume (quantity) or value (amount spent) indices.
ons_retail_sales( type = c("volume", "value"), from = NULL, to = NULL, cache = TRUE )ons_retail_sales( type = c("volume", "value"), from = NULL, to = NULL, cache = TRUE )
type |
Character. One of |
from |
Date or character (YYYY-MM-DD). Start date. Defaults to
|
to |
Date or character (YYYY-MM-DD). End date. Defaults to |
cache |
Logical. Use cached data if available (default |
A data frame with columns:
Date. First day of the month.
Numeric. Retail sales index.
Other trade and prices:
ons_house_prices(),
ons_trade()
op <- options(ons.cache_dir = tempdir()) try(ons_retail_sales(from = "2020-01-01")) options(op)op <- options(ons.cache_dir = tempdir()) try(ons_retail_sales(from = "2020-01-01")) options(op)
Searches the ONS catalogue for time series matching a keyword or phrase.
Returns CDID codes, titles, and dataset information that can be used with
ons_get().
ons_search(query, limit = 10L)ons_search(query, limit = 10L)
query |
Character. Search term (e.g. |
limit |
Integer. Maximum number of results to return (default 10, maximum 50). |
A data frame with columns:
Character. The four-character CDID code.
Character. The ONS dataset identifier.
Character. Description of the series.
Character. Date of the most recent release.
Other data access:
clear_cache(),
ons_get()
op <- options(ons.cache_dir = tempdir()) try(ons_search("GDP growth")) options(op)op <- options(ons.cache_dir = tempdir()) try(ons_search("GDP growth")) options(op)
Downloads UK trade in goods and services data from the ONS. Available from 1948.
ons_trade( measure = c("balance", "exports", "imports"), from = NULL, to = NULL, cache = TRUE )ons_trade( measure = c("balance", "exports", "imports"), from = NULL, to = NULL, cache = TRUE )
measure |
Character. One of |
from |
Date or character (YYYY-MM-DD). Start date. Defaults to
|
to |
Date or character (YYYY-MM-DD). End date. Defaults to |
cache |
Logical. Use cached data if available (default |
A data frame with columns:
Date. First day of the month.
Numeric. Trade value (GBP millions).
Other trade and prices:
ons_house_prices(),
ons_retail_sales()
op <- options(ons.cache_dir = tempdir()) try(ons_trade(from = "2020-01-01")) options(op)op <- options(ons.cache_dir = tempdir()) try(ons_trade(from = "2020-01-01")) options(op)
Downloads the UK unemployment rate (aged 16 and over, seasonally adjusted) from the ONS Labour Market Statistics. Available from 1971.
ons_unemployment(from = NULL, to = NULL, cache = TRUE)ons_unemployment(from = NULL, to = NULL, cache = TRUE)
from |
Date or character (YYYY-MM-DD). Start date. Defaults to
|
to |
Date or character (YYYY-MM-DD). End date. Defaults to |
cache |
Logical. Use cached data if available (default |
A data frame with columns:
Date. First day of the period.
Numeric. Unemployment rate (percent).
Other labour market:
ons_employment(),
ons_inactivity(),
ons_wages()
op <- options(ons.cache_dir = tempdir()) try(ons_unemployment(from = "2020-01-01")) options(op)op <- options(ons.cache_dir = tempdir()) try(ons_unemployment(from = "2020-01-01")) options(op)
Downloads average weekly earnings (AWE) for the whole economy from the ONS Labour Market Statistics. Available from 2000.
ons_wages( measure = c("level", "growth", "real"), from = NULL, to = NULL, cache = TRUE )ons_wages( measure = c("level", "growth", "real"), from = NULL, to = NULL, cache = TRUE )
measure |
Character. One of |
from |
Date or character (YYYY-MM-DD). Start date. Defaults to
|
to |
Date or character (YYYY-MM-DD). End date. Defaults to |
cache |
Logical. Use cached data if available (default |
A data frame with columns:
Date. First day of the month.
Numeric. Earnings level (GBP), growth rate (percent), or real index.
Other labour market:
ons_employment(),
ons_inactivity(),
ons_unemployment()
op <- options(ons.cache_dir = tempdir()) try(ons_wages(from = "2020-01-01")) options(op)op <- options(ons.cache_dir = tempdir()) try(ons_wages(from = "2020-01-01")) options(op)