-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add geography lookup data and functions (#81)
* Initial code to query ONS API * WIP: add lookup data from ONS API * Working wd_pcon_lad_la file, needs tidying, documentation improvements and tests * still WIP, got mostly working but a few data issues (going to need to squash these commits!) * got fetch_ons_api batching up okay * update column order in description * add verbose toggle and general WIP * general package tidying * removed multiple years and stopped returning time cols in fetch functions * WIP: two todo's left to fix * Everything finally works! * add examples to readme, fix up pkgdown site * Initial code to query ONS API * WIP: add lookup data from ONS API * Working wd_pcon_lad_la file, needs tidying, documentation improvements and tests * still WIP, got mostly working but a few data issues (going to need to squash these commits!) * got fetch_ons_api batching up okay * update column order in description * add verbose toggle and general WIP * general package tidying * removed multiple years and stopped returning time cols in fetch functions * WIP: two todo's left to fix * Everything finally works! * add examples to readme, fix up pkgdown site * Quick refactor of the create_project() code to prevent linting issues * remove notes in contributing * tidy up wordlist * fix issue in api wrapper * code to add country information * add countries data set * add rgn, gor, ctry to shorthands * extend to join on region and country, add fetch region and ward * tidy URLs in data set sources * Increment version number to 0.5.0 * add regions * add regions into pkgdown yml * shuffle shuffle (to <family>_utils.R and binning helper_functions.R) * typo fix in test file naming * tighten up check_fetch_location_inputs * Update countries and regions to use year variables at start of scripts * Move to 4 digit years and improve documentation * Add a section to the contributing guide about the geography data * update function comments * add internal link into contributing * add rich's error guidance * fix typo
- Loading branch information
Showing
68 changed files
with
2,889 additions
and
431 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
^CODE_OF_CONDUCT\.md$ | ||
^codecov\.yml$ | ||
^README\.Rmd$ | ||
^data-raw$ |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Type: Package | ||
Package: dfeR | ||
Title: Common DfE R tasks | ||
Version: 0.4.1 | ||
Version: 0.5.0 | ||
Authors@R: c( | ||
person("Cam", "Race", , "[email protected]", role = c("aut", "cre")), | ||
person("Laura", "Selby", , "[email protected]", role = "aut"), | ||
|
@@ -18,22 +18,33 @@ License: GPL (>= 3) | |
URL: https://dfe-analytical-services.github.io/dfeR/, | ||
https://github.com/dfe-analytical-services/dfeR | ||
BugReports: https://github.com/dfe-analytical-services/dfeR/issues | ||
Depends: | ||
R (>= 2.10) | ||
Imports: | ||
dplyr, | ||
emoji, | ||
httr, | ||
jsonlite, | ||
lifecycle, | ||
magrittr, | ||
renv, | ||
rlang, | ||
tidyselect, | ||
usethis, | ||
utils, | ||
withr | ||
Suggests: | ||
knitr, | ||
readxl, | ||
rmarkdown, | ||
spelling, | ||
stringr, | ||
testthat (>= 3.0.0) | ||
VignetteBuilder: | ||
knitr | ||
Config/testthat/edition: 3 | ||
Encoding: UTF-8 | ||
Language: en-GB | ||
LazyData: true | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.3.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#' Lookup for ONS geography columns shorthands | ||
#' | ||
#' A lookup of ONS geography shorthands and their respective column names in | ||
#' line with DfE open data standards. | ||
#' | ||
#' GOR (Government Office Region) was the predecessor to RGN. | ||
#' | ||
#' @format ## `ons_geog_shorthands` | ||
#' A data frame with 7 rows and 3 columns: | ||
#' \describe{ | ||
#' \item{ons_level_shorthands}{ONS shorthands used in their lookup files} | ||
#' \item{name_column}{DfE names for geography name columns} | ||
#' \item{code_column}{DfE names for geography code columns} | ||
#' } | ||
#' @source curated by explore.statistics@@education.gov.uk | ||
"ons_geog_shorthands" | ||
|
||
#' Ward to Constituency to LAD to LA to Region to Country lookup | ||
#' | ||
#' A lookup showing the hierarchy of ward to Westminster parliamentary | ||
#' constituency to local authority district to local authority to region to | ||
#' country for years 2017, 2019, 2020, 2021, 2022, 2023 and 2024. | ||
#' | ||
#' Changes we've made to the original lookup: | ||
#' 1. The original lookup from ONS uses the Upper Tier Local Authority, we then | ||
#' update this so that where there is a metropolitan local authority we use the | ||
#' local authority district as the local authority to match how | ||
#' DfE publish data for local authorities. | ||
#' | ||
#' 2. We have noticed that in the 2017 version, the Glasgow East constituency | ||
#' had a code of S1400030 instead of the usual S14000030, we've assumed this | ||
#' was an error and have change this in our data so that Glasgow East is | ||
#' S14000030 in 2017. | ||
#' | ||
#' 3. We have joined on regions using the Ward to LAD to County to Region file. | ||
#' | ||
#' 4. We have joined on countries based on the E / N / S / W at the start of | ||
#' codes. | ||
#' | ||
#' 5. Scotland had no published regions in 2017, so given the rest of the years | ||
#' have Scotland as the region, we've forced that in for 2017 too to complete | ||
#' the data set. | ||
#' | ||
#' @format ## `wd_pcon_lad_la_rgn_ctry` | ||
#' A data frame with 24,629 rows and 14 columns: | ||
#' \describe{ | ||
#' \item{first_available_year_included}{ | ||
#' First year in the lookups that we see this location | ||
#' } | ||
#' \item{most_recent_year_included}{ | ||
#' Last year in the lookups that we see this location | ||
#' } | ||
#' \item{ward_name}{Ward name} | ||
#' \item{pcon_name}{Parliamentary constituency name} | ||
#' \item{lad_name}{Local authority district name} | ||
#' \item{la_name}{Local authority name} | ||
#' \item{region_name}{Region name} | ||
#' \item{country_code}{Country name} | ||
#' \item{ward_code}{9 digit ward code} | ||
#' \item{pcon_code}{9 digit westminster constituency code} | ||
#' \item{lad_code}{9 digit local authority district code} | ||
#' \item{new_la_code}{9 digit local authority code} | ||
#' \item{region_code}{9 digit region code} | ||
#' \item{country_code}{9 digit country code} | ||
#' } | ||
#' @source https://geoportal.statistics.gov.uk/search?tags=lup_wd_pcon_lad_utla | ||
#' and https://geoportal.statistics.gov.uk/search?q=lup_wd_lad_cty_rgn_gor_ctry | ||
"wd_pcon_lad_la_rgn_ctry" | ||
|
||
#' Lookup for valid country names and codes | ||
#' | ||
#' A lookup of ONS geography country names and codes, as well as some custom | ||
#' DfE names and codes. This is used as the definitive list for the screening | ||
#' of open data before it is published by the DfE. | ||
#' | ||
#' @format ## `countries` | ||
#' A data frame with 10 rows and 2 columns: | ||
#' \describe{ | ||
#' \item{country_name}{Country name} | ||
#' \item{country_code}{Country code} | ||
#' } | ||
#' @source curated by explore.statistics@@education.gov.uk, ONS codes sourced | ||
#' from | ||
#' https://geoportal.statistics.gov.uk/search?q=countries%20names%20and%20codes | ||
"countries" | ||
|
||
#' Lookup for valid region names and codes | ||
#' | ||
#' A lookup of ONS geography region names and codes for England. In their | ||
#' lookups Northern Ireland, Scotland and Wales are regions. | ||
#' | ||
#' Also included inner and outer London county split as DfE frequently publish | ||
#' those as regions, as well as some custom DfE names and codes. This is used | ||
#' as the definitive list for the screening of open data before it is published | ||
#' by the DfE. | ||
#' | ||
#' @format ## `regions` | ||
#' A data frame with 16 rows and 2 columns: | ||
#' \describe{ | ||
#' \item{region_name}{Region name} | ||
#' \item{region_code}{Region code} | ||
#' } | ||
#' @source curated by explore.statistics@@education.gov.uk, ONS codes sourced | ||
#' from | ||
#' https://geoportal.statistics.gov.uk/search?q=NAC_RGN | ||
"regions" |
Oops, something went wrong.