Open Lextuga007 opened 3 days ago
Hi @Lextuga007 I am pretty sure this will be resulting from the fact that the IMD data endpoint used in NHSRpopulation::api_url
no longer exists (or rather, it is currently reporting a "Token required" error message).
Let me know if you would like me to share some alternative code for getting the IMD data.
My suggestion would be that the IMD 2019 table should be stored as static internal package data in the package, as it is fixed data and doesn't need to be retrieved fresh from an API each time it is needed.
Ironically that's how this package started 😂 with a static dataset! @milanwiedemann may find this point of interest!
It's a bit annoying because the whole point of a data API endpoint is they're not supposed to just disappear! But I am sure there are reasons why they sometimes do.
This is what I'm using in my package here instead now:
imd_lookup <- function() {
# https://www.gov.uk/government/statistics/english-indices-of-deprivation-2019
base <- "https://assets.publishing.service.gov.uk/media/"
fold <- "5d8b3abded915d0373d3540f/"
file <- "File_1_-_IMD2019_Index_of_Multiple_Deprivation.xlsx"
paste0(base, fold, file) |>
openxlsx2::read_xlsx(sheet = "IMD2019") |>
tibble::as_tibble() |>
janitor::clean_names() |>
dplyr::rename_with(\(x) c(
"lsoa11cd",
"lsoa11nm",
"lad19cd",
"lad19nm",
"imd_rank",
"imd_decile"
)) |>
dplyr::mutate(across(starts_with("imd"), as.integer)) |>
dplyr::mutate(across("imd_decile", as.factor))
}
imd_lookup <- imd_lookup()
usethis::use_data(imd_lookup, overwrite = TRUE)
From the Health Inequalities book:
And a simplified code: