From 80d29ac8729e18c6ad07aa3810166ebe7590991b Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Tue, 7 Nov 2023 16:24:59 +0000 Subject: [PATCH 1/3] change get_datazone_pop_path to get_pop_path to allow for more types --- NAMESPACE | 2 +- R/get_lookup_paths.R | 31 ++++++++++++++----- man/get_gpprac_ref_path.Rd | 2 +- man/get_locality_path.Rd | 2 +- man/get_lookups_dir.Rd | 2 +- ...t_datazone_pop_path.Rd => get_pop_path.Rd} | 14 ++++++--- man/get_simd_path.Rd | 2 +- man/get_spd_path.Rd | 2 +- man/read_file.Rd | 2 +- 9 files changed, 39 insertions(+), 20 deletions(-) rename man/{get_datazone_pop_path.Rd => get_pop_path.Rd} (71%) diff --git a/NAMESPACE b/NAMESPACE index c9ffc03d2..e6191f84e 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..bedbcfea8 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,33 @@ 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} diff --git a/man/read_file.Rd b/man/read_file.Rd index 1ef351342..b8231218f 100644 --- a/man/read_file.Rd +++ b/man/read_file.Rd @@ -14,7 +14,7 @@ read_file(path, col_select = NULL, as_data_frame = TRUE, ...) \link[tidyselect:eval_select]{tidy selection specification} of columns, as used in \code{dplyr::select()}.} -\item{as_data_frame}{Should the function return a \code{tibble} (default) or +\item{as_data_frame}{Should the function return a \code{data.frame} (default) or an Arrow \link[arrow]{Table}?} \item{...}{Addition arguments passed to the relevant function.} From 20bdb6abdd736fec832d9ed3dc02e0c41287d20f Mon Sep 17 00:00:00 2001 From: lizihao-anu Date: Tue, 7 Nov 2023 16:29:05 +0000 Subject: [PATCH 2/3] Update documentation --- man/read_file.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/read_file.Rd b/man/read_file.Rd index b8231218f..1ef351342 100644 --- a/man/read_file.Rd +++ b/man/read_file.Rd @@ -14,7 +14,7 @@ read_file(path, col_select = NULL, as_data_frame = TRUE, ...) \link[tidyselect:eval_select]{tidy selection specification} of columns, as used in \code{dplyr::select()}.} -\item{as_data_frame}{Should the function return a \code{data.frame} (default) or +\item{as_data_frame}{Should the function return a \code{tibble} (default) or an Arrow \link[arrow]{Table}?} \item{...}{Addition arguments passed to the relevant function.} From c45c67eb5ed469a20749885d1043a67542c535bc Mon Sep 17 00:00:00 2001 From: lizihao-anu Date: Tue, 7 Nov 2023 16:35:29 +0000 Subject: [PATCH 3/3] Style code --- R/get_lookup_paths.R | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/R/get_lookup_paths.R b/R/get_lookup_paths.R index bedbcfea8..fe35a7d2f 100644 --- a/R/get_lookup_paths.R +++ b/R/get_lookup_paths.R @@ -107,11 +107,13 @@ get_simd_path <- function(file_name = NULL, ext = "parquet") { #' @family lookup file paths get_pop_path <- function(file_name = NULL, ext = "rds", - type = c("datazone", - "hscp", - "ca", - "hb", - "intzone")) { + type = c( + "datazone", + "hscp", + "ca", + "hb", + "intzone" + )) { pop_dir <- fs::path(get_lookups_dir(), "Populations", "Estimates")