|
| 1 | +library(tidyverse) |
| 2 | +library(readxl) |
| 3 | + |
| 4 | +# Load package |
| 5 | +devtools::load_all(".") |
| 6 | + |
| 7 | +# Set query url |
| 8 | +query_url <- |
| 9 | + query_urls |> |
| 10 | + filter(data_set == "imd_soa_ni") |> |
| 11 | + pull(query_url) |
| 12 | + |
| 13 | +httr::GET( |
| 14 | + query_url, |
| 15 | + httr::write_disk(tf <- tempfile(fileext = ".xls")) |
| 16 | +) |
| 17 | + |
| 18 | +# ---- Income ---- |
| 19 | +income <- read_excel(tf, sheet = "Income") |
| 20 | + |
| 21 | +income <- income |> |
| 22 | + select(soa_code = SOA2001, starts_with("Proportion")) |
| 23 | + |
| 24 | +# ---- Employment ---- |
| 25 | +employment <- read_excel(tf, sheet = "Employment") |
| 26 | + |
| 27 | +employment <- employment |> |
| 28 | + select(soa_code = SOA2001, starts_with("Proportion")) |
| 29 | + |
| 30 | +# ---- Health and Disability ---- |
| 31 | +health <- read_excel(tf, sheet = "Health and Disability") |
| 32 | + |
| 33 | +health <- health |> |
| 34 | + select(-1, -2, -4, -5) |> |
| 35 | + rename(soa_code = SOA2001) |
| 36 | + |
| 37 | +# ---- Education ---- |
| 38 | +education <- read_excel(tf, sheet = "Education, Skills and Training ") |
| 39 | + |
| 40 | +education <- education |> |
| 41 | + select(-1, -2, -4, -5) |> |
| 42 | + rename(soa_code = SOA2001) |
| 43 | + |
| 44 | +# ---- Access to services ---- |
| 45 | +access <- read_excel(tf, sheet = "Access to Services") |
| 46 | + |
| 47 | +access <- access |> |
| 48 | + select(-1, -2, -4, -5) |> |
| 49 | + rename(soa_code = SOA2001) |
| 50 | + |
| 51 | +# ---- Living environment ---- |
| 52 | +env <- read_excel(tf, sheet = "Living Environment") |
| 53 | + |
| 54 | +env <- env |> |
| 55 | + select(-1, -2, -4, -5) |> |
| 56 | + rename(soa_code = SOA2001) |
| 57 | + |
| 58 | +# ---- Crime and disorder ---- |
| 59 | +crime <- read_excel(tf, sheet = "Crime and Disorder") |
| 60 | + |
| 61 | +crime <- crime |> |
| 62 | + select(-1, -2, -4, -5) |> |
| 63 | + rename(soa_code = SOA2001) |
| 64 | + |
| 65 | +# ---- IDAC and IDAP ---- |
| 66 | +ida <- read_excel(tf, sheet = "IDAC and IDAP") |
| 67 | + |
| 68 | +ida <- ida |> |
| 69 | + select(-1, -2, -4) |> |
| 70 | + rename(soa_code = SOA2001) |
| 71 | + |
| 72 | +# ---- Combine ---- |
| 73 | +imd2017_soa01_northern_ireland <- |
| 74 | + income |> |
| 75 | + left_join(employment) |> |
| 76 | + left_join(health) |> |
| 77 | + left_join(education) |> |
| 78 | + left_join(access) |> |
| 79 | + left_join(env) |> |
| 80 | + left_join(crime) |> |
| 81 | + left_join(ida) |
| 82 | + |
| 83 | +# Save output to data/ folder |
| 84 | +usethis::use_data(imd2017_soa01_northern_ireland, overwrite = TRUE) |
| 85 | +readr::write_csv(imd2017_soa01_northern_ireland, "data-raw/imd2017_soa01_northern_ireland.csv") |
0 commit comments