Interact with the UK AIR Pollution Database from DEFRA

Get data from DEFRA's UK-AIR website <>. It basically scrapes the HTML content.

DOI status

Travis-CI Build Status

CRAN Status Badge CRAN Total Downloads CRAN Monthly Downloads

The package rdefra allows to retrieve air pollution data from the Air Information Resource UK-AIR of the Department for Environment, Food and Rural Affairs in the United Kingdom. UK-AIR does not provide a public API for programmatic access to data, therefore this package scrapes the HTML pages to get relevant information.

This package follows a logic similar to other packages such as waterData and rnrfa: sites are first identified through a catalogue, data are imported via the station identification number, then data are visualised and/or used in analyses. The metadata related to the monitoring stations are accessible through the function ukair_catalogue(), missing stations' coordinates can be obtained using the function ukair_get_coordinates(), and time series data related to different pollutants can be obtained using the function ukair_get_hourly_data().

DEFRA's servers can handle multiple data requests, therefore concurrent calls can be sent simultaneously using the parallel package. Although the limit rate depends on the maximum number of concurrent calls, traffic and available infrustracture, data retrieval is very efficient. Multiple years of data for hundreds of sites can be downloaded in only few minutes.

For similar functionalities see also the openair package, which relies on a local copy of the data on servers at King's College (UK), and the ropenaq which provides UK-AIR latest measured levels (see as well as data from other countries.

Dependencies & Installation

The rdefra package depends on two things:

  • The Geospatial Data Abstraction Library (gdal).

  • Some additional CRAN packages. Check for missing dependencies and install them using the commands below:

packs <- c('httr', 'xml2', 'lubridate', 'tibble', 'dplyr', 'sp', 'devtools',
           'leaflet', 'zoo', 'testthat', 'knitr', 'Rmarkdown')
new.packages <- packs[!(packs %in% installed.packages()[,'Package'])]
if(length(new.packages)) install.packages(new.packages)


Get the released version from CRAN:


Or the development version from github using devtools:


Load the rdefra package:



The package logic assumes that users access the UK-AIR database in the fllowing steps:

  1. Browse the catalogue of available stations and selects some stations of interest (see function ukair_catalogue()).
  2. Get missing coordinates (see function ukair_get_coordinates()).
  3. Retrieves data for the selected stations (see functions ukair_get_site_id() and ukair_get_hourly_data()).

For an in-depth description of the various functionalities andexample applications, please refer to the package vignette.


  • Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
  • Please report any issues or bugs.
  • License: GPL-3
  • This package was reviewed by Maëlle Salmon and Hao Zhu for submission to ROpenSci (see review here) and the Journal of Open Source Software (see review here).
  • Get citation information for rdefra in R doing citation(package = 'rdefra')



rdefra 0.3.5


Functions are updated due to a recent modification of the catalogue API.


Changes made after scanning the package using goodpractice:

  • lines no longer than 80 characters
  • 84% code coverage
  • function names shorter than 30 characters
    • function ukair_get_coordinates now renamed ukair_get_coords

rdefra 0.3.4


Changes to DESCRIPTION file:

  • Added rmarkdown and knitr in Suggests
  • Added entry VignetteBuilder: knitr
  • Changed all links to the new ropenscilabs github account (ropenscilabs instead of kehraProject)

This repo is now transferred to the ropenscilabs github account.

rdefra 0.3.3

In this release the package was moved to the root directory (needed based on the ropensci review) and the related adjustments made.


  • Corrected units in README (#2)
  • Merged README_files folder to assets? (#3)

rdefra 0.3.2

Accepted for pubblication on JOSS

rdefra 0.3.1

Minor changes

rdefra 0.3.0

Minor fixes

rdefra 0.2.0

  • Added unist tests (using testthat framework),
  • Added Travis CI integration
  • Added a vignette
  • Added paper for submission to JOSS
  • Added a document to review the package under the ropensci project

rdefra 0.1.0

  • Initial release

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.3.8 by Claudia Vitolo, 10 months ago,

Report a bug at

Browse source code at

Authors: Claudia Vitolo [aut, cre] , Andrew Russell [ctb] (This package is part of the KEHRA project and Andrew supervised the technical/software development.) , Allan Tucker [ctb] (This package is part of the KEHRA project and Allan supervised the technical/software development.) , Maëlle Salmon [ctb] (Maëlle Salmon reviewed the package for rOpenSci , see , Hao Zhu [ctb] (Hao Zhu reviewed the package for rOpenSci , see

Documentation:   PDF Manual  

GPL-3 license

Imports lubridate, tibble, httr, xml2, dplyr, sp, rgdal

Suggests testthat, rmarkdown, knitr, ggplot2, zoo

System requirements: GDAL

See at CRAN