| Title: | Access 'Nomis' UK Labour Market Data and Statistics |
|---|---|
| Description: | Interface to the 'Nomis' database (<https://www.nomisweb.co.uk>), maintained by Durham University on behalf of the Office for National Statistics (ONS). Provides access to UK labour market statistics including census data, benefit claimant counts, and employment surveys. Supports automatic pagination, optional disk caching, spatial data via 'sf', and tidy data output. Independent implementation unaffiliated with ONS or Durham University. |
| Authors: | Cheryl Isabella Lim [aut, cre] (ORCID: <https://orcid.org/0009-0004-5766-1392>) |
| Maintainer: | Cheryl Isabella Lim <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.2 |
| Built: | 2026-05-10 09:42:33 UTC |
| Source: | https://github.com/cherylisabella/nomisdata |
Adds human-readable geography names to data.
add_geography_names(data, dataset_id = "NM_1_1")add_geography_names(data, dataset_id = "NM_1_1")
data |
Data frame with GEOGRAPHY_CODE column |
dataset_id |
Dataset to get geography names from |
Data frame with GEOGRAPHY_NAME added
data <- fetch_nomis("NM_1_1", time = "latest", geography = "TYPE499") data_with_names <- add_geography_names(data)data <- fetch_nomis("NM_1_1", time = "latest", geography = "TYPE499") data_with_names <- add_geography_names(data)
Aggregates data to higher geography levels.
aggregate_geography(data, to_type, value_col = "OBS_VALUE", fun = sum)aggregate_geography(data, to_type, value_col = "OBS_VALUE", fun = sum)
data |
Data frame with geography codes |
to_type |
Target geography TYPE code |
value_col |
Column containing values to aggregate (default: "OBS_VALUE") |
fun |
Aggregation function (default: sum) |
A tibble with aggregated data grouped by specified variables.
data(jsa_sample) aggregated <- aggregate_geography(jsa_sample, "TYPE499", "OBS_VALUE") head(aggregated)data(jsa_sample) aggregated <- aggregate_geography(jsa_sample, "TYPE499", "OBS_VALUE") head(aggregated)
Aggregates data over time periods.
aggregate_time( data, period = c("year", "quarter", "month"), value_col = "OBS_VALUE", fun = mean )aggregate_time( data, period = c("year", "quarter", "month"), value_col = "OBS_VALUE", fun = mean )
data |
Data frame with DATE column |
period |
Aggregation period: "year", "quarter", "month" |
value_col |
Column containing values to aggregate |
fun |
Aggregation function (default: mean) |
A tibble with PERIOD column and aggregated values.
data(jsa_sample) if ("DATE" %in% names(jsa_sample)) { yearly_data <- aggregate_time(jsa_sample, "year", "OBS_VALUE") }data(jsa_sample) if ("DATE" %in% names(jsa_sample)) { yearly_data <- aggregate_time(jsa_sample, "year", "OBS_VALUE") }
Opens the Nomis web interface for a dataset in your browser.
browse_dataset(id, page = c("dataset", "download", "metadata"))browse_dataset(id, page = c("dataset", "download", "metadata"))
id |
Dataset ID (e.g., "NM_1_1") |
page |
Which page to open: "dataset", "download", "metadata" |
Invisible TRUE if successful. Called for side effects (opening browser).
## Not run: browse_dataset("NM_1_1") browse_dataset("NM_1_1", page = "download") ## End(Not run)## Not run: browse_dataset("NM_1_1") browse_dataset("NM_1_1", page = "download") ## End(Not run)
Removes all cached data.
Removes all cached data from disk and clears memoised functions.
clear_cache() clear_cache()clear_cache() clear_cache()
Invisible TRUE. Called for side effects.
Invisible TRUE. Called for side effects (clearing cache files).
enable_cache() clear_cache() enable_cache(tempfile("nomis_cache")) clear_cache()enable_cache() clear_cache() enable_cache(tempfile("nomis_cache")) clear_cache()
Get Dataset Overview
dataset_overview(id, select = NULL)dataset_overview(id, select = NULL)
id |
Dataset ID (required) |
select |
Character vector of sections to return |
Tibble with overview information
dataset_overview("NM_1_1") dataset_overview("NM_1_1", select = c("Keywords", "Units"))dataset_overview("NM_1_1") dataset_overview("NM_1_1", select = c("Keywords", "Units"))
Describe Dataset Structure
describe_dataset(id = NULL)describe_dataset(id = NULL)
id |
Dataset ID (e.g., "NM_1_1"). If NULL, returns all datasets. |
Tibble with dataset metadata
describe_dataset("NM_1_1") all_datasets <- describe_dataset()describe_dataset("NM_1_1") all_datasets <- describe_dataset()
Enable caching for API responses
enable_cache(path = NULL)enable_cache(path = NULL)
path |
Cache directory path. If NULL, uses an appropriate default location. |
Path to cache directory (invisibly)
# Use temporary directory for cache enable_cache(tempfile("nomis_cache"))# Use temporary directory for cache enable_cache(tempfile("nomis_cache"))
Opens an interactive menu to explore dataset dimensions and codes. Only works in interactive R sessions.
explore_dataset(id)explore_dataset(id)
id |
Dataset ID |
Selected codes as a list, or NULL if not interactive.
## Not run: # Only works in interactive sessions explore_dataset("NM_1_1") ## End(Not run)## Not run: # Only works in interactive sessions explore_dataset("NM_1_1") ## End(Not run)
Fetch Codelist
fetch_codelist(id, concept, search = NULL)fetch_codelist(id, concept, search = NULL)
id |
Dataset ID |
concept |
Concept name |
search |
Search term |
Tibble of codes
fetch_codelist("NM_1_1", "geography") fetch_codelist("NM_1_1", "geography", "*manchester*")fetch_codelist("NM_1_1", "geography") fetch_codelist("NM_1_1", "geography", "*manchester*")
Main function to download data from Nomis datasets.
fetch_nomis( id, time = NULL, date = NULL, geography = NULL, sex = NULL, measures = NULL, exclude_missing = FALSE, select = NULL, ..., .progress = interactive() )fetch_nomis( id, time = NULL, date = NULL, geography = NULL, sex = NULL, measures = NULL, exclude_missing = FALSE, select = NULL, ..., .progress = interactive() )
id |
Dataset ID (required) |
time |
Time range using keywords or specific dates |
date |
Specific dates (alternative to time) |
geography |
Geography code(s) |
sex |
Sex/gender code(s) |
measures |
Measure code(s) |
exclude_missing |
Remove missing values |
select |
Column names to include |
... |
Additional dimension filters |
.progress |
Show progress bar for multi-part queries |
Tibble with requested data
fetch_nomis( "NM_1_1", time = "latest", geography = "TYPE499", measures = 20100, sex = 7 ) fetch_nomis( "NM_1_1", date = c("latest", "prevyear"), geography = c("2092957697", "2092957698"), measures = 20100 )fetch_nomis( "NM_1_1", time = "latest", geography = "TYPE499", measures = 20100, sex = 7 ) fetch_nomis( "NM_1_1", date = c("latest", "prevyear"), geography = c("2092957697", "2092957698"), measures = 20100 )
Downloads data in KML format with spatial boundaries.
fetch_spatial( id, time = NULL, date = NULL, geography = NULL, select = NULL, exclude_missing = FALSE, ..., parse_sf = TRUE )fetch_spatial( id, time = NULL, date = NULL, geography = NULL, select = NULL, exclude_missing = FALSE, ..., parse_sf = TRUE )
id |
Dataset ID |
time |
Time period selection (same as fetch_nomis) |
date |
Specific date selection (alternative to time) |
geography |
Geography code(s) to filter |
select |
Column names to include |
exclude_missing |
Remove missing values if TRUE |
... |
Additional query parameters (measures, sex, etc.) |
parse_sf |
If TRUE and sf is available, parse to sf object |
KML data as text or sf object (if parse_sf = TRUE)
spatial_data <- fetch_spatial( "NM_1_1", time = "latest", geography = "TYPE480", measures = 20100, sex = 7 )spatial_data <- fetch_spatial( "NM_1_1", time = "latest", geography = "TYPE480", measures = 20100, sex = 7 )
Get Concept Codes
get_codes(id, concept = NULL, type = NULL, search = NULL, ...)get_codes(id, concept = NULL, type = NULL, search = NULL, ...)
id |
Dataset ID (required) |
concept |
Concept name (e.g., "geography", "sex"). If NULL, returns all concepts. |
type |
Optional type filter |
search |
Search term (supports wildcards) |
... |
Additional query parameters |
Tibble with codes and descriptions
get_codes("NM_1_1") get_codes("NM_1_1", "geography") get_codes("NM_1_1", "geography", "TYPE499") get_codes("NM_1_1", "geography", search = "*manchester*")get_codes("NM_1_1") get_codes("NM_1_1", "geography") get_codes("NM_1_1", "geography", "TYPE499") get_codes("NM_1_1", "geography", search = "*manchester*")
A small sample dataset from the Jobseeker's Allowance dataset (NM_1_1) for the UK, Great Britain, and England. Useful for offline examples and testing.
jsa_samplejsa_sample
A tibble with 3 rows and 12 columns:
ONS geography code
Geography name (UK, GB, England)
Sex code (7 = Total)
Sex description
Item code
Item description
Measure code (20100)
Measure description
Date code (YYYY-MM format)
Date description
Observed value (number of claimants)
Observation status code
Number of records in query
Nomis API: https://www.nomisweb.co.uk
data(jsa_sample) head(jsa_sample) summary(jsa_sample$OBS_VALUE)data(jsa_sample) head(jsa_sample) summary(jsa_sample$OBS_VALUE)
Search for UK geography codes by name. Returns matching geographies from local authorities, regions, wards, and other levels.
lookup_geography(search_term, dataset_id = "NM_1_1", type = NULL)lookup_geography(search_term, dataset_id = "NM_1_1", type = NULL)
search_term |
Name or partial name to search (e.g., "London", "Manchester") |
dataset_id |
Dataset to search in (default: "NM_1_1") |
type |
Optional geography TYPE code to filter results |
Tibble of matching geographies with codes and names
lookup_geography("London") lookup_geography("Manchester") lookup_geography("Birmingham", type = "TYPE464") # Local authorities onlylookup_geography("London") lookup_geography("Manchester") lookup_geography("Birmingham", type = "TYPE464") # Local authorities only
Search for Datasets
search_datasets( name = NULL, keywords = NULL, description = NULL, content_type = NULL, units = NULL )search_datasets( name = NULL, keywords = NULL, description = NULL, content_type = NULL, units = NULL )
name |
Character vector of name search terms (supports wildcards *) |
keywords |
Character vector of keyword search terms |
description |
Character vector of description search terms |
content_type |
Character vector of content types |
units |
Character vector of units |
Tibble of matching datasets
search_datasets(name = "*employment*") search_datasets(keywords = "census") search_datasets(name = "*benefit*", keywords = "claimants")search_datasets(name = "*employment*") search_datasets(keywords = "census") search_datasets(name = "*benefit*", keywords = "claimants")
Configure your Nomis API key for increased rate limits. Register at: https://www.nomisweb.co.uk/myaccount/userjoin.asp
set_api_key(key = NULL, persist = FALSE)set_api_key(key = NULL, persist = FALSE)
key |
API key string. If NULL, will prompt or check environment. |
persist |
If TRUE, saves to .Renviron for future sessions. |
Invisible TRUE if successful
set_api_key("your-key-here") set_api_key("your-key-here", persist = TRUE)set_api_key("your-key-here") set_api_key("your-key-here", persist = TRUE)
Tidy Column Names
tidy_names(df, style = "snake_case")tidy_names(df, style = "snake_case")
df |
Data frame |
style |
Naming style: "snake_case", "camelCase", "period.case" |
Data frame with tidied names
df <- data.frame(GEOGRAPHY_NAME = "UK", OBS_VALUE = 100) tidy_names(df)df <- data.frame(GEOGRAPHY_NAME = "UK", OBS_VALUE = 100) tidy_names(df)