-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
360296f
commit d11e5dc
Showing
7 changed files
with
126 additions
and
224 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
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,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) |
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,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 not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.