Skip to content

Commit

Permalink
Delete old postcode lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewgthomas committed Mar 5, 2025
1 parent 360296f commit d11e5dc
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 224 deletions.
38 changes: 0 additions & 38 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -1245,44 +1245,6 @@
#' @source \url{https://geoportal.statistics.gov.uk/}
"lookup_postcode_dz21_sdz21_dea14_lgd14"

#' Postcode to Output Area (2011) to Lower Layer Super Output Area (2011) to
#' Middle Layer Super Output Area (2011) to Local Authority District (2020)
#' Lookup
#'
#' A data set containing a lookup between postcodes, OAs, LSOAs, MSOAs, and
#' 2020 Local Authority Districts, for England, Wales, and Scotland.
#'
#' @format A data frame of class "tbl" with 2,568,780 rows and 5 variables:
#' \describe{
#' \item{postcode}{Postcodes}
#' \item{oa11_code}{OA code}
#' \item{lsoa11_code}{LSOA code}
#' \item{msoa11_code}{MSOA code}
#' \item{ltla20_code}{LAD code}
#' ...
#' }
#' @source \url{https://geoportal.statistics.gov.uk/}
"lookup_postcode_oa11_lsoa11_msoa11_ltla20"

#' Postcode to Output Area (2021) to Lower Layer Super Output Area (2021) to
#' Middle Layer Super Output Area (2021) to Local Authority District (2022)
#' Lookup
#'
#' A data set containing a lookup between postcodes, OAs, LSOAs, MSOAs, and
#' 2022 Local Authority Districts, for England, Wales, and Scotland.
#'
#' @format A data frame of class "tbl" with 2,600,236 rows and 5 variables:
#' \describe{
#' \item{postcode}{Postcodes}
#' \item{oa21_code}{OA code}
#' \item{lsoa21_code}{LSOA code}
#' \item{msoa21_code}{MSOA code}
#' \item{ltla22_code}{LAD code}
#' ...
#' }
#' @source \url{https://geoportal.statistics.gov.uk/}
"lookup_postcode_oa21_lsoa21_msoa21_ltla22"

#' Postcode (2025) to Output Area (2011 and 2021) to Lower Layer Super Output Area
#' (2011 and 2021) to Middle Layer Super Output Area (2011 and 2021) to Local
#' Authority District (2024) Lookup
Expand Down
126 changes: 63 additions & 63 deletions data-raw/lookup_postcode_oa11_lsoa11_msoa11_ltla20.R
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
# ---- Load ----
library(tidyverse)
library(devtools)
library(httr)

# Load package
load_all(".")

# Set query url
query_url <-
query_urls |>
filter(id == "postcode_oa11_lsoa11_msoa11_ltla20") |>
pull(query)

# GET and unzip file
GET(
query_url,
write_disk(zip_folder <- tempfile(fileext = ".zip"))
)

unzip(zip_folder, exdir = tempdir())

file <- file.path(tempdir(), "NSPCL_NOV20_UK_LU.csv")

postcodes <-
read_csv(file)

# Select and rename vars
postcode_oa_lsoa_msoa_lad <-
postcodes |>
select(
postcode = pcds,
oa11_code = oa11cd,
lsoa11_code = lsoa11cd,
msoa11_code = msoa11cd,
ltla20_code = ladcd
)

# Keep distinct values and clean postcode column
postcode_oa_lsoa_msoa_lad <-
postcode_oa_lsoa_msoa_lad |>
mutate(postcode = str_to_upper(postcode)) |>
mutate(postcode = str_remove_all(postcode, " ")) |>
distinct()

# Remove NI Postcodes which are distributed under their own license:
# https://www.ons.gov.uk/methodology/geography/licences

# Keep only Valid codes, as two "pseudo" codes appear in the data:
# "L99999999" & "M99999999"
postcode_oa_lsoa_msoa_lad <-
postcode_oa_lsoa_msoa_lad |>
filter(
str_detect(ltla20_code, "^E") |
str_detect(ltla20_code, "^W") |
str_detect(ltla20_code, "^S")
)

# Rename
lookup_postcode_oa11_lsoa11_msoa11_ltla20 <- postcode_oa_lsoa_msoa_lad

# Save output to data/ folder
usethis::use_data(lookup_postcode_oa11_lsoa11_msoa11_ltla20, overwrite = TRUE)
# # ---- Load ----
# library(tidyverse)
# library(devtools)
# library(httr)
#
# # Load package
# load_all(".")
#
# # Set query url
# query_url <-
# query_urls |>
# filter(id == "postcode_oa11_lsoa11_msoa11_ltla20") |>
# pull(query)
#
# # GET and unzip file
# GET(
# query_url,
# write_disk(zip_folder <- tempfile(fileext = ".zip"))
# )
#
# unzip(zip_folder, exdir = tempdir())
#
# file <- file.path(tempdir(), "NSPCL_NOV20_UK_LU.csv")
#
# postcodes <-
# read_csv(file)
#
# # Select and rename vars
# postcode_oa_lsoa_msoa_lad <-
# postcodes |>
# select(
# postcode = pcds,
# oa11_code = oa11cd,
# lsoa11_code = lsoa11cd,
# msoa11_code = msoa11cd,
# ltla20_code = ladcd
# )
#
# # Keep distinct values and clean postcode column
# postcode_oa_lsoa_msoa_lad <-
# postcode_oa_lsoa_msoa_lad |>
# mutate(postcode = str_to_upper(postcode)) |>
# mutate(postcode = str_remove_all(postcode, " ")) |>
# distinct()
#
# # Remove NI Postcodes which are distributed under their own license:
# # https://www.ons.gov.uk/methodology/geography/licences
#
# # Keep only Valid codes, as two "pseudo" codes appear in the data:
# # "L99999999" & "M99999999"
# postcode_oa_lsoa_msoa_lad <-
# postcode_oa_lsoa_msoa_lad |>
# filter(
# str_detect(ltla20_code, "^E") |
# str_detect(ltla20_code, "^W") |
# str_detect(ltla20_code, "^S")
# )
#
# # Rename
# lookup_postcode_oa11_lsoa11_msoa11_ltla20 <- postcode_oa_lsoa_msoa_lad
#
# # Save output to data/ folder
# usethis::use_data(lookup_postcode_oa11_lsoa11_msoa11_ltla20, overwrite = TRUE)
126 changes: 63 additions & 63 deletions data-raw/lookup_postcode_oa21_lsoa21_msoa21_ltla22.R
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
# ---- Load ----
library(tidyverse)
library(devtools)
library(httr)

# Load package
load_all(".")

# Set query url
query_url <-
query_urls |>
filter(id == "postcode_oa21_lsoa21_msoa21_ltla22") |>
pull(query)

# GET and unzip file
GET(
query_url,
write_disk(zip_folder <- tempfile(fileext = ".zip"))
)

unzip(zip_folder, exdir = tempdir())

file <- file.path(tempdir(), "PCD_OA21_LSOA21_MSOA21_LAD_NOV22_UK_LU.csv")

postcodes <-
read_csv(file)

# Select and rename vars
postcode_oa_lsoa_msoa_lad <-
postcodes |>
select(
postcode = pcds,
oa21_code = oa21cd,
lsoa21_code = lsoa21cd,
msoa21_code = msoa21cd,
ltla22_code = ladcd
)

# Keep distinct values and clean postcode column
postcode_oa_lsoa_msoa_lad <-
postcode_oa_lsoa_msoa_lad |>
mutate(postcode = str_to_upper(postcode)) |>
mutate(postcode = str_remove_all(postcode, " ")) |>
distinct()

# Remove NI Postcodes which are distributed under their own license:
# https://www.ons.gov.uk/methodology/geography/licences

# Keep only Valid codes, as two "pseudo" codes appear in the data:
# "L99999999" & "M99999999"
postcode_oa_lsoa_msoa_lad <-
postcode_oa_lsoa_msoa_lad |>
filter(
str_detect(ltla22_code, "^E") |
str_detect(ltla22_code, "^W") |
str_detect(ltla22_code, "^S")
)

# Rename
lookup_postcode_oa21_lsoa21_msoa21_ltla22 <- postcode_oa_lsoa_msoa_lad

# Save output to data/ folder
usethis::use_data(lookup_postcode_oa21_lsoa21_msoa21_ltla22, overwrite = TRUE)
# # ---- Load ----
# library(tidyverse)
# library(devtools)
# library(httr)
#
# # Load package
# load_all(".")
#
# # Set query url
# query_url <-
# query_urls |>
# filter(id == "postcode_oa21_lsoa21_msoa21_ltla22") |>
# pull(query)
#
# # GET and unzip file
# GET(
# query_url,
# write_disk(zip_folder <- tempfile(fileext = ".zip"))
# )
#
# unzip(zip_folder, exdir = tempdir())
#
# file <- file.path(tempdir(), "PCD_OA21_LSOA21_MSOA21_LAD_NOV22_UK_LU.csv")
#
# postcodes <-
# read_csv(file)
#
# # Select and rename vars
# postcode_oa_lsoa_msoa_lad <-
# postcodes |>
# select(
# postcode = pcds,
# oa21_code = oa21cd,
# lsoa21_code = lsoa21cd,
# msoa21_code = msoa21cd,
# ltla22_code = ladcd
# )
#
# # Keep distinct values and clean postcode column
# postcode_oa_lsoa_msoa_lad <-
# postcode_oa_lsoa_msoa_lad |>
# mutate(postcode = str_to_upper(postcode)) |>
# mutate(postcode = str_remove_all(postcode, " ")) |>
# distinct()
#
# # Remove NI Postcodes which are distributed under their own license:
# # https://www.ons.gov.uk/methodology/geography/licences
#
# # Keep only Valid codes, as two "pseudo" codes appear in the data:
# # "L99999999" & "M99999999"
# postcode_oa_lsoa_msoa_lad <-
# postcode_oa_lsoa_msoa_lad |>
# filter(
# str_detect(ltla22_code, "^E") |
# str_detect(ltla22_code, "^W") |
# str_detect(ltla22_code, "^S")
# )
#
# # Rename
# lookup_postcode_oa21_lsoa21_msoa21_ltla22 <- postcode_oa_lsoa_msoa_lad
#
# # Save output to data/ folder
# usethis::use_data(lookup_postcode_oa21_lsoa21_msoa21_ltla22, overwrite = TRUE)
Binary file removed data/lookup_postcode_oa11_lsoa11_msoa11_ltla20.rda
Binary file not shown.
Binary file removed data/lookup_postcode_oa21_lsoa21_msoa21_ltla22.rda
Binary file not shown.
30 changes: 0 additions & 30 deletions man/lookup_postcode_oa11_lsoa11_msoa11_ltla20.Rd

This file was deleted.

30 changes: 0 additions & 30 deletions man/lookup_postcode_oa21_lsoa21_msoa21_ltla22.Rd

This file was deleted.

0 comments on commit d11e5dc

Please sign in to comment.