Learn R Programming

Overview

The sgapi package provides a simple wrapper around the nomis and Open Geography Portal APIs, aiding geospatial analysis of the population, labour market, and social measures. Simplifies process of querying nomis datasets and extracting area shapefiles at chosen resolution from ONS Open Geography.

The authors thank ONS for their work in maintaining both NOMIS and Open Geography Portal, without them this work would not be possible.

More information on theses sources can be found here:

ONS Open Geography Portal

nomis

Users must abide by the licensing agreements when publishing information extracted from these ONS sources, for more copyright information, see the copyright section.

Installation

 install.packages("sgapi")
 

Install Development Version

install.packages("remotes")
remotes::install_github("https://github.com/Defra-Data-Science-Centre-of-Excellence/sgapi")

Quick start

# List available nomis tables
list_tables()

# Pull all data from the "Jobseeker's Allowance" dataset
get_ons_table("nm_1_1")

# Filter "Jobseeker's Allowance" dataset and 'select' columns to output
get_ons_table("nm_1_1",
              geography = "TYPE480", time = "latest", measures = 20100, item = 1,
              select = c("geography_name", "sex_name", "obs_value"))

# Aggregate statistics using 'rows' and 'cols'
get_ons_table("nm_1_1",
              geography = "TYPE480", time = "latest", measures = 20100, item = 1,
              select = c("geography_name", "sex_name", "obs_value"),
              rows = c("geography_name"), cols = c("sex_name"))

Key Functions

  1. get_boundaries.R - returns shapefile of areas in contact with a user selected rectangular area, at your chosen ONS resolution
  2. get_boundaries_areanames.R - returns the shapefiles for all areas input into the function.
  3. get_table_dimensions.R - for a chosen nomis table this function returns all of the parameters which can be filtered
  4. get_ons_table.R - extracts a dataframe from the chosen nomis table for your selected area and selected filters
  5. get_table_link_lookup.R - retrieves a dataframe with the lookup table between two resolutions, taken from ONS Open Geography lookup tables
  6. get_table_info_brief.R - returns summary information for the selected nomis table, including contact details, data description and table status

Exploratory Functions

  1. list_boundaries.R - lists all boundary masks available on the ONS Open Geography
  2. list_tables.R - lists all tables, including their name and reference code, from nomis
  3. get_available_scales.R - provides list of available geographical resolutions for your chosen nomis table
  4. list_data_sources.R - lists all available data sources on nomis

Additional API Information

ONS Open Geography Portal

nomis

Copyright and Permissions

ONS Open Geography Portal

Terms and conditions of supply Digital boundary products and reference maps are supplied under the Open Government Licence. You must use the following copyright statements when you reproduce or use this material:

Source: Office for National Statistics licensed under the Open Government Licence v.3.0 Contains OS data © Crown copyright and database right [year]

nomis

All material on the Office for National Statistics (ONS) and Nomis websites is subject to Crown Copyright protection unless otherwise indicated.

Source: Office for National Statistics

For more information on the Open Government Licence, see the open government license

Copy Link

Version

Install

install.packages('sgapi')

Monthly Downloads

152

Version

1.1.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Andrew Christy

Last Published

December 1st, 2025

Functions in sgapi (1.1.2)

get_available_scales

Available Boundary Scales for 'nomis' Table
get_boundaries

Get Boundaries Using Geospatial Filter
availableBoundaries.rda

List of available ONS boundaries
assert_function

Escape Function in Case of Errors
get_boundaries_areaname

Get Boundaries Using Area Names
get_overview

Table Overview
get_keyword_table_id

Keyword Search of 'nomis'
get_ons_table

Get ONS data
build_constituency_query_string

Build constituency section of get_boundary_areaname query string
build_url_query_string

Build URL Query String
list_tables

Available 'nomis' Tables
get_table_link_lookup

Lookup Between Boundary Scales
get_structure

Extract 'nomis' Table Data for Chosen Dimension
get_table_info_brief

Key 'nomis' Table Information
get_table_dimensions

Table Dimensions
lookup.rda

Lookup to match Office for National Statistics (ONS) and 'nomis' boundary names
nomisTables.rda

#' List of tables on 'nomis'
get_table

Get 'nomis' Table
list_data_sources

List 'nomis' Data Sources
scalesForEachDataset.rda

#' List of tables available at each ONS resolution
get_table_id

Get 'nomis 'Table IDs