diff --git a/NAMESPACE b/NAMESPACE index 9df952e0f..670ed1932 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -27,7 +27,6 @@ export(find_latest_file) export(fy_interval) export(get_boxi_extract_path) export(get_ch_costs_path) -export(get_datazone_pop_path) export(get_dd_path) export(get_dd_period) export(get_demographic_cohorts_path) @@ -52,6 +51,7 @@ export(get_locality_path) export(get_lookups_dir) export(get_ltcs_path) export(get_nsu_path) +export(get_pop_path) export(get_practice_details_path) export(get_readcode_lookup_path) export(get_sc_at_episodes_path) diff --git a/R/get_lookup_paths.R b/R/get_lookup_paths.R index cc11f8d4d..fe35a7d2f 100644 --- a/R/get_lookup_paths.R +++ b/R/get_lookup_paths.R @@ -94,10 +94,10 @@ get_simd_path <- function(file_name = NULL, ext = "parquet") { return(simd_path) } -# TODO update this function to look for a specified type of pop estimate e.g. datazone, hscp etc. -#' Datazone Populations File Path + +#' Populations File Path for different types #' -#' @description Get the path to the Datazone populations estimates +#' @description Get the path to the populations estimates #' #' @inheritParams get_file_path #' @@ -105,18 +105,35 @@ get_simd_path <- function(file_name = NULL, ext = "parquet") { #' @export #' #' @family lookup file paths -get_datazone_pop_path <- function(file_name = NULL, ext = "rds") { - datazone_pop_dir <- +get_pop_path <- function(file_name = NULL, + ext = "rds", + type = c( + "datazone", + "hscp", + "ca", + "hb", + "intzone" + )) { + pop_dir <- fs::path(get_lookups_dir(), "Populations", "Estimates") + file_name_re <- dplyr::case_match( + type, + "datazone" ~ stringr::str_glue("DataZone2011_pop_est_2011_\\d+?\\.{ext}"), + "hscp" ~ stringr::str_glue("HSCP2019_pop_est_1981_\\d+?\\.{ext}"), + "ca" ~ stringr::str_glue("CA2019_pop_est_1981_\\d+?\\.{ext}"), + "hb" ~ stringr::str_glue("HB2019_pop_est_1981_\\d+?\\.{ext}"), + "intzone" ~ stringr::str_glue("IntZone_pop_est_2011_\\d+?\\.{ext}") + ) + datazone_pop_path <- get_file_path( - directory = datazone_pop_dir, + directory = pop_dir, file_name = file_name, ext = ext, - file_name_regexp = stringr::str_glue("DataZone2011_pop_est_2001_\\d+?\\.{ext}") + file_name_regexp = file_name_re ) - return(datazone_pop_path) + return(pop_path) } diff --git a/man/get_gpprac_ref_path.Rd b/man/get_gpprac_ref_path.Rd index d8990cd95..a61a4b560 100644 --- a/man/get_gpprac_ref_path.Rd +++ b/man/get_gpprac_ref_path.Rd @@ -17,9 +17,9 @@ Get the path for the centrally held reference file \code{gpprac} } \seealso{ Other lookup file paths: -\code{\link{get_datazone_pop_path}()}, \code{\link{get_locality_path}()}, \code{\link{get_lookups_dir}()}, +\code{\link{get_pop_path}()}, \code{\link{get_simd_path}()}, \code{\link{get_spd_path}()} } diff --git a/man/get_locality_path.Rd b/man/get_locality_path.Rd index a09bad48e..65f809b2f 100644 --- a/man/get_locality_path.Rd +++ b/man/get_locality_path.Rd @@ -19,9 +19,9 @@ Get the path to the centrally held HSCP Localities file. } \seealso{ Other lookup file paths: -\code{\link{get_datazone_pop_path}()}, \code{\link{get_gpprac_ref_path}()}, \code{\link{get_lookups_dir}()}, +\code{\link{get_pop_path}()}, \code{\link{get_simd_path}()}, \code{\link{get_spd_path}()} } diff --git a/man/get_lookups_dir.Rd b/man/get_lookups_dir.Rd index e1748b9a8..4e90472bf 100644 --- a/man/get_lookups_dir.Rd +++ b/man/get_lookups_dir.Rd @@ -14,9 +14,9 @@ Get the path to the lookups directory } \seealso{ Other lookup file paths: -\code{\link{get_datazone_pop_path}()}, \code{\link{get_gpprac_ref_path}()}, \code{\link{get_locality_path}()}, +\code{\link{get_pop_path}()}, \code{\link{get_simd_path}()}, \code{\link{get_spd_path}()} diff --git a/man/get_datazone_pop_path.Rd b/man/get_pop_path.Rd similarity index 71% rename from man/get_datazone_pop_path.Rd rename to man/get_pop_path.Rd index 45b1edbca..ce9c0409c 100644 --- a/man/get_datazone_pop_path.Rd +++ b/man/get_pop_path.Rd @@ -1,10 +1,14 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_lookup_paths.R -\name{get_datazone_pop_path} -\alias{get_datazone_pop_path} -\title{Datazone Populations File Path} +\name{get_pop_path} +\alias{get_pop_path} +\title{Populations File Path for different types} \usage{ -get_datazone_pop_path(file_name = NULL, ext = "rds") +get_pop_path( + file_name = NULL, + ext = "rds", + type = c("datazone", "hscp", "ca", "hb", "intzone") +) } \arguments{ \item{file_name}{The file name (with extension if not supplied to \code{ext})} @@ -15,7 +19,7 @@ get_datazone_pop_path(file_name = NULL, ext = "rds") An \code{\link[fs:path]{fs::path()}} to the populations estimates file } \description{ -Get the path to the Datazone populations estimates +Get the path to the populations estimates } \seealso{ Other lookup file paths: diff --git a/man/get_simd_path.Rd b/man/get_simd_path.Rd index 6d5cc1b93..15e58929e 100644 --- a/man/get_simd_path.Rd +++ b/man/get_simd_path.Rd @@ -20,10 +20,10 @@ Deprivation (SIMD) file. } \seealso{ Other lookup file paths: -\code{\link{get_datazone_pop_path}()}, \code{\link{get_gpprac_ref_path}()}, \code{\link{get_locality_path}()}, \code{\link{get_lookups_dir}()}, +\code{\link{get_pop_path}()}, \code{\link{get_spd_path}()} } \concept{lookup file paths} diff --git a/man/get_spd_path.Rd b/man/get_spd_path.Rd index 70a5f00be..25d46f114 100644 --- a/man/get_spd_path.Rd +++ b/man/get_spd_path.Rd @@ -20,10 +20,10 @@ Get the path to the centrally held Scottish Postcode Directory } \seealso{ Other lookup file paths: -\code{\link{get_datazone_pop_path}()}, \code{\link{get_gpprac_ref_path}()}, \code{\link{get_locality_path}()}, \code{\link{get_lookups_dir}()}, +\code{\link{get_pop_path}()}, \code{\link{get_simd_path}()} } \concept{lookup file paths}