From c7b65a834176911f8294da426cd81796ff51d5fa Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Tue, 8 Aug 2023 15:33:28 +0100 Subject: [PATCH 1/9] New function for SLF final file paths --- NAMESPACE | 2 ++ R/get_final_file_paths.R | 30 ++++++++++++++++++++++++++++++ man/get_slf_episode_path.Rd | 17 +++++++++++++++++ man/get_slf_individual_path.Rd | 17 +++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 R/get_final_file_paths.R create mode 100644 man/get_slf_episode_path.Rd create mode 100644 man/get_slf_individual_path.Rd diff --git a/NAMESPACE b/NAMESPACE index 6c4f3cd52..e7356169d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -59,7 +59,9 @@ export(get_slf_ch_name_lookup_path) export(get_slf_chi_deaths_path) export(get_slf_deaths_lookup_path) export(get_slf_dir) +export(get_slf_episode_path) export(get_slf_gpprac_path) +export(get_slf_individual_path) export(get_slf_postcode_path) export(get_source_extract_path) export(get_sparra_path) diff --git a/R/get_final_file_paths.R b/R/get_final_file_paths.R new file mode 100644 index 000000000..6f86264d5 --- /dev/null +++ b/R/get_final_file_paths.R @@ -0,0 +1,30 @@ +#' Get the slf episode file path +#' +#' @param year Financial year +#' +#' @return Path to the final episode file. +#' @export +#' +get_slf_episode_path <- function(year) { + slf_episode_path <- get_file_path( + get_year_dir(year), + stringr::str_glue("source-episode-file-{year}.parquet") + ) + + return(slf_episode_path) +} + +#' Get the SLF individual file path +#' +#' @param year Financial year +#' +#' @return Path to the final individual file +#' @export +#' +get_slf_individual_path <- function(year) { + slf_indiv_path <- get_file_path( + get_year_dir(year), + stringr::str_glue("source-individual-file-{year}.parquet") + ) + return(slf_indiv_path) +} diff --git a/man/get_slf_episode_path.Rd b/man/get_slf_episode_path.Rd new file mode 100644 index 000000000..ca7b871ac --- /dev/null +++ b/man/get_slf_episode_path.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_final_file_paths.R +\name{get_slf_episode_path} +\alias{get_slf_episode_path} +\title{Get the slf episode file path} +\usage{ +get_slf_episode_path(year) +} +\arguments{ +\item{year}{Financial year} +} +\value{ +Path to the final episode file. +} +\description{ +Get the slf episode file path +} diff --git a/man/get_slf_individual_path.Rd b/man/get_slf_individual_path.Rd new file mode 100644 index 000000000..9586803ad --- /dev/null +++ b/man/get_slf_individual_path.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_final_file_paths.R +\name{get_slf_individual_path} +\alias{get_slf_individual_path} +\title{Get the SLF individual file path} +\usage{ +get_slf_individual_path(year) +} +\arguments{ +\item{year}{Financial year} +} +\value{ +Path to the final individual file +} +\description{ +Get the SLF individual file path +} From fe295544298f100d5ae8005d15ad4d4c6ac7bb7c Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Tue, 8 Aug 2023 15:34:40 +0100 Subject: [PATCH 2/9] Implement final file path functions --- R/create_individual_file.R | 8 +------- R/run_episode_file.R | 10 ++-------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/R/create_individual_file.R b/R/create_individual_file.R index f0e6bcdfc..461b1f6b9 100644 --- a/R/create_individual_file.R +++ b/R/create_individual_file.R @@ -82,13 +82,7 @@ create_individual_file <- function( } if (write_to_disk) { - slf_indiv_path <- get_file_path( - get_year_dir(year), - stringr::str_glue( - "source-individual-file-{year}.parquet" - ), - check_mode = "write" - ) + slf_indiv_path <- get_slf_individual_path(year) write_file(individual_file, slf_indiv_path) } diff --git a/R/run_episode_file.R b/R/run_episode_file.R index 19c2481f2..841007cb3 100644 --- a/R/run_episode_file.R +++ b/R/run_episode_file.R @@ -116,14 +116,8 @@ run_episode_file <- function( } if (write_to_disk) { - # TODO make the slf_path a function - slf_episode_path <- get_file_path( - get_year_dir(year), - stringr::str_glue( - "source-episode-file-{year}.parquet" - ), - check_mode = "write" - ) + + slf_episode_path <- get_slf_episode_path(year) write_file(episode_file, slf_episode_path) } From 5a4ee3ac694b23cac601922a1f3eb71533f3e1e4 Mon Sep 17 00:00:00 2001 From: Jennit07 Date: Tue, 8 Aug 2023 14:38:29 +0000 Subject: [PATCH 3/9] Style code --- R/run_episode_file.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/run_episode_file.R b/R/run_episode_file.R index 841007cb3..29f6859a1 100644 --- a/R/run_episode_file.R +++ b/R/run_episode_file.R @@ -116,7 +116,6 @@ run_episode_file <- function( } if (write_to_disk) { - slf_episode_path <- get_slf_episode_path(year) write_file(episode_file, slf_episode_path) From 930381527aee9d8dc4ba5177eb8360a4d2ab0306 Mon Sep 17 00:00:00 2001 From: Jennit07 Date: Mon, 25 Sep 2023 08:32:57 +0000 Subject: [PATCH 4/9] 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 1adca3f1f28c8971439d182e30081eebe3d1724a Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Tue, 26 Sep 2023 14:37:13 +0100 Subject: [PATCH 5/9] Update final file paths to use `...` --- R/create_individual_file.R | 2 +- R/get_final_file_paths.R | 16 ++++++++++------ R/run_episode_file.R | 2 +- man/get_slf_episode_path.Rd | 4 +++- man/get_slf_individual_path.Rd | 4 +++- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/R/create_individual_file.R b/R/create_individual_file.R index 461b1f6b9..b43ab7eb8 100644 --- a/R/create_individual_file.R +++ b/R/create_individual_file.R @@ -82,7 +82,7 @@ create_individual_file <- function( } if (write_to_disk) { - slf_indiv_path <- get_slf_individual_path(year) + slf_indiv_path <- get_slf_individual_path(year, check_mode = "write") write_file(individual_file, slf_indiv_path) } diff --git a/R/get_final_file_paths.R b/R/get_final_file_paths.R index 6f86264d5..f47250621 100644 --- a/R/get_final_file_paths.R +++ b/R/get_final_file_paths.R @@ -1,14 +1,16 @@ #' Get the slf episode file path #' #' @param year Financial year +#' @param ... additional arguments passed to [get_file_path()] #' #' @return Path to the final episode file. #' @export #' -get_slf_episode_path <- function(year) { +get_slf_episode_path <- function(year, ...) { slf_episode_path <- get_file_path( - get_year_dir(year), - stringr::str_glue("source-episode-file-{year}.parquet") + directory = get_year_dir(year), + file_name = stringr::str_glue("source-episode-file-{year}.parquet"), + ... ) return(slf_episode_path) @@ -17,14 +19,16 @@ get_slf_episode_path <- function(year) { #' Get the SLF individual file path #' #' @param year Financial year +#' @param ... additional arguments passed to [get_file_path()] #' #' @return Path to the final individual file #' @export #' -get_slf_individual_path <- function(year) { +get_slf_individual_path <- function(year, ...) { slf_indiv_path <- get_file_path( - get_year_dir(year), - stringr::str_glue("source-individual-file-{year}.parquet") + directory = get_year_dir(year), + file_name = stringr::str_glue("source-individual-file-{year}.parquet"), + ... ) return(slf_indiv_path) } diff --git a/R/run_episode_file.R b/R/run_episode_file.R index 29f6859a1..9a9b0c53c 100644 --- a/R/run_episode_file.R +++ b/R/run_episode_file.R @@ -116,7 +116,7 @@ run_episode_file <- function( } if (write_to_disk) { - slf_episode_path <- get_slf_episode_path(year) + slf_episode_path <- get_slf_episode_path(year, check_mode = "write") write_file(episode_file, slf_episode_path) } diff --git a/man/get_slf_episode_path.Rd b/man/get_slf_episode_path.Rd index ca7b871ac..064e47fbb 100644 --- a/man/get_slf_episode_path.Rd +++ b/man/get_slf_episode_path.Rd @@ -4,10 +4,12 @@ \alias{get_slf_episode_path} \title{Get the slf episode file path} \usage{ -get_slf_episode_path(year) +get_slf_episode_path(year, ...) } \arguments{ \item{year}{Financial year} + +\item{...}{additional arguments passed to \code{\link[=get_file_path]{get_file_path()}}} } \value{ Path to the final episode file. diff --git a/man/get_slf_individual_path.Rd b/man/get_slf_individual_path.Rd index 9586803ad..9b72c6d89 100644 --- a/man/get_slf_individual_path.Rd +++ b/man/get_slf_individual_path.Rd @@ -4,10 +4,12 @@ \alias{get_slf_individual_path} \title{Get the SLF individual file path} \usage{ -get_slf_individual_path(year) +get_slf_individual_path(year, ...) } \arguments{ \item{year}{Financial year} + +\item{...}{additional arguments passed to \code{\link[=get_file_path]{get_file_path()}}} } \value{ Path to the final individual file From c5fa97bb7e14bede27d22878349612ca5bd77c4f Mon Sep 17 00:00:00 2001 From: marjom02 Date: Tue, 26 Sep 2023 14:54:27 +0100 Subject: [PATCH 6/9] fixing conflicts with `run episode file` getting renamed to `create episode file` --- R/{run_episode_file.R => create_episode_file.R} | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) rename R/{run_episode_file.R => create_episode_file.R} (97%) diff --git a/R/run_episode_file.R b/R/create_episode_file.R similarity index 97% rename from R/run_episode_file.R rename to R/create_episode_file.R index 9a9b0c53c..1f81f53c5 100644 --- a/R/run_episode_file.R +++ b/R/create_episode_file.R @@ -1,16 +1,15 @@ -#' Produce the Source Episode file +#' Create the Source Episode file #' #' @param processed_data_list containing data from processed extracts. #' @param year The year to process, in FY format. #' @param write_to_disk (optional) Should the data be written to disk default is #' `TRUE` i.e. write the data to disk. #' @param anon_chi_out (Default:TRUE) Should `anon_chi` be used in the output -#' (instead of chi) +#' (instead of chi). #' -#' @return a [tibble][tibble::tibble-package] containing the episode file +#' @return the Source Episode file as a [tibble][tibble::tibble-package]. #' @export -#' -run_episode_file <- function( +create_episode_file <- function( processed_data_list, year, write_to_disk = TRUE, @@ -122,12 +121,13 @@ run_episode_file <- function( } return(episode_file) + } #' Store the unneeded episode file variables #' #' @param data The in-progress episode file data. -#' @inheritParams run_episode_file +#' @inheritParams create_episode_file #' @param vars_to_keep a character vector of the variables to keep, all others #' will be stored. #' @@ -165,7 +165,7 @@ store_ep_file_vars <- function(data, year, vars_to_keep) { #' Load the unneeded episode file variables #' -#' @inheritParams run_episode_file +#' @inheritParams create_episode_file #' @inheritParams store_ep_file_vars #' #' @return The full SLF data. From 68fead9527c13368f9e83eac0809f79519a44926 Mon Sep 17 00:00:00 2001 From: SwiftySalmon Date: Tue, 26 Sep 2023 13:57:10 +0000 Subject: [PATCH 7/9] Update documentation --- NAMESPACE | 2 +- man/clean_up_ch.Rd | 2 -- man/correct_cij_vars.Rd | 2 +- man/create_cohort_lookups.Rd | 2 +- man/create_cost_inc_dna.Rd | 2 +- ...un_episode_file.Rd => create_episode_file.Rd} | 16 ++++++++-------- man/create_individual_file.Rd | 8 -------- man/fill_missing_cij_markers.Rd | 2 +- man/join_cohort_lookups.Rd | 2 +- man/load_ep_file_vars.Rd | 2 +- man/store_ep_file_vars.Rd | 2 +- 11 files changed, 16 insertions(+), 26 deletions(-) rename man/{run_episode_file.Rd => create_episode_file.Rd} (63%) diff --git a/NAMESPACE b/NAMESPACE index e7356169d..b10de16be 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -13,6 +13,7 @@ export(convert_hscp_to_hscpnames) export(convert_numeric_to_date) export(convert_sending_location_to_lca) export(convert_year_to_fyyear) +export(create_episode_file) export(create_individual_file) export(create_service_use_cohorts) export(end_fy) @@ -157,7 +158,6 @@ export(read_sc_all_alarms_telecare) export(read_sc_all_care_home) export(read_sc_all_home_care) export(read_sc_all_sds) -export(run_episode_file) export(start_fy) export(start_fy_quarter) export(start_next_fy_quarter) diff --git a/man/clean_up_ch.Rd b/man/clean_up_ch.Rd index 0182c84e8..932a68b1b 100644 --- a/man/clean_up_ch.Rd +++ b/man/clean_up_ch.Rd @@ -8,8 +8,6 @@ clean_up_ch(episode_file, year) } \arguments{ \item{episode_file}{Tibble containing episodic data} - -\item{year}{The year to process, in FY format.} } \description{ Clean up CH-related columns. diff --git a/man/correct_cij_vars.Rd b/man/correct_cij_vars.Rd index 97a7f046f..558514dc6 100644 --- a/man/correct_cij_vars.Rd +++ b/man/correct_cij_vars.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/run_episode_file.R +% Please edit documentation in R/create_episode_file.R \name{correct_cij_vars} \alias{correct_cij_vars} \title{Correct the CIJ variables} diff --git a/man/create_cohort_lookups.Rd b/man/create_cohort_lookups.Rd index f0ad267aa..109869074 100644 --- a/man/create_cohort_lookups.Rd +++ b/man/create_cohort_lookups.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/run_episode_file.R +% Please edit documentation in R/create_episode_file.R \name{create_cohort_lookups} \alias{create_cohort_lookups} \title{Create the cohort lookups} diff --git a/man/create_cost_inc_dna.Rd b/man/create_cost_inc_dna.Rd index 69e7e37b5..47c38b176 100644 --- a/man/create_cost_inc_dna.Rd +++ b/man/create_cost_inc_dna.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/run_episode_file.R +% Please edit documentation in R/create_episode_file.R \name{create_cost_inc_dna} \alias{create_cost_inc_dna} \title{Create cost total net inc DNA} diff --git a/man/run_episode_file.Rd b/man/create_episode_file.Rd similarity index 63% rename from man/run_episode_file.Rd rename to man/create_episode_file.Rd index 59d5fea1d..e1bda32b9 100644 --- a/man/run_episode_file.Rd +++ b/man/create_episode_file.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/run_episode_file.R -\name{run_episode_file} -\alias{run_episode_file} -\title{Produce the Source Episode file} +% Please edit documentation in R/create_episode_file.R +\name{create_episode_file} +\alias{create_episode_file} +\title{Create the Source Episode file} \usage{ -run_episode_file( +create_episode_file( processed_data_list, year, write_to_disk = TRUE, @@ -20,11 +20,11 @@ run_episode_file( \code{TRUE} i.e. write the data to disk.} \item{anon_chi_out}{(Default:TRUE) Should \code{anon_chi} be used in the output -(instead of chi)} +(instead of chi).} } \value{ -a \link[tibble:tibble-package]{tibble} containing the episode file +the Source Episode file as a \link[tibble:tibble-package]{tibble}. } \description{ -Produce the Source Episode file +Create the Source Episode file } diff --git a/man/create_individual_file.Rd b/man/create_individual_file.Rd index fa759e7b1..9b9f16648 100644 --- a/man/create_individual_file.Rd +++ b/man/create_individual_file.Rd @@ -15,16 +15,8 @@ create_individual_file( \arguments{ \item{episode_file}{Tibble containing episodic data} -\item{year}{The year to process, in FY format.} - -\item{write_to_disk}{(optional) Should the data be written to disk default is -\code{TRUE} i.e. write the data to disk.} - \item{anon_chi_in}{(Default:TRUE) Is \code{anon_chi} used in the input (instead of chi)} - -\item{anon_chi_out}{(Default:TRUE) Should \code{anon_chi} be used in the output -(instead of chi)} } \value{ The processed individual file diff --git a/man/fill_missing_cij_markers.Rd b/man/fill_missing_cij_markers.Rd index 03b64217e..4795eed7a 100644 --- a/man/fill_missing_cij_markers.Rd +++ b/man/fill_missing_cij_markers.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/run_episode_file.R +% Please edit documentation in R/create_episode_file.R \name{fill_missing_cij_markers} \alias{fill_missing_cij_markers} \title{Fill any missing CIJ markers for records that should have them} diff --git a/man/join_cohort_lookups.Rd b/man/join_cohort_lookups.Rd index 445dcd7c0..15a860a36 100644 --- a/man/join_cohort_lookups.Rd +++ b/man/join_cohort_lookups.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/run_episode_file.R +% Please edit documentation in R/create_episode_file.R \name{join_cohort_lookups} \alias{join_cohort_lookups} \title{Join cohort lookups} diff --git a/man/load_ep_file_vars.Rd b/man/load_ep_file_vars.Rd index cee9cc440..509b0e00c 100644 --- a/man/load_ep_file_vars.Rd +++ b/man/load_ep_file_vars.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/run_episode_file.R +% Please edit documentation in R/create_episode_file.R \name{load_ep_file_vars} \alias{load_ep_file_vars} \title{Load the unneeded episode file variables} diff --git a/man/store_ep_file_vars.Rd b/man/store_ep_file_vars.Rd index 06316aac1..880266d58 100644 --- a/man/store_ep_file_vars.Rd +++ b/man/store_ep_file_vars.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/run_episode_file.R +% Please edit documentation in R/create_episode_file.R \name{store_ep_file_vars} \alias{store_ep_file_vars} \title{Store the unneeded episode file variables} From 7d75dee40f59d0a734a50bf7e5d553323b12c43b Mon Sep 17 00:00:00 2001 From: SwiftySalmon Date: Tue, 26 Sep 2023 14:10:46 +0000 Subject: [PATCH 8/9] Update documentation --- man/create_episode_file.Rd | 4 ---- man/create_individual_file.Rd | 6 +++++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/man/create_episode_file.Rd b/man/create_episode_file.Rd index a6415485d..3ce6c815d 100644 --- a/man/create_episode_file.Rd +++ b/man/create_episode_file.Rd @@ -2,7 +2,6 @@ % Please edit documentation in R/create_episode_file.R \name{create_episode_file} \alias{create_episode_file} - \title{Produce the Source Episode file} \usage{ create_episode_file( @@ -15,7 +14,6 @@ create_episode_file( slf_gpprac_lookup = read_file(get_slf_gpprac_path(), col_select = c("gpprac", "cluster", "hbpraccode")), slf_deaths_lookup = read_file(get_slf_deaths_lookup_path(year)), - write_to_disk = TRUE, anon_chi_out = TRUE ) @@ -25,7 +23,6 @@ create_episode_file( \item{year}{The year to process, in FY format.} - \item{dd_data}{The processed DD extract} \item{nsu_cohort}{The NSU data for the year} @@ -42,7 +39,6 @@ create_episode_file( \code{TRUE} i.e. write the data to disk.} \item{anon_chi_out}{(Default:TRUE) Should \code{anon_chi} be used in the output - (instead of chi)} } \value{ diff --git a/man/create_individual_file.Rd b/man/create_individual_file.Rd index ce3f991d4..2b54de366 100644 --- a/man/create_individual_file.Rd +++ b/man/create_individual_file.Rd @@ -15,8 +15,12 @@ create_individual_file( \arguments{ \item{episode_file}{Tibble containing episodic data.} -\item{anon_chi_in}{(Default:TRUE) Is \code{anon_chi} used in the input +\item{year}{The year to process, in FY format.} + +\item{write_to_disk}{(optional) Should the data be written to disk default is +\code{TRUE} i.e. write the data to disk.} +\item{anon_chi_in}{(Default:TRUE) Is \code{anon_chi} used in the input (instead of chi).} \item{anon_chi_out}{(Default:TRUE) Should \code{anon_chi} be used in the output From a16d7e62f5bd9cec1e0920558d9554ffc8b8bb30 Mon Sep 17 00:00:00 2001 From: SwiftySalmon Date: Tue, 26 Sep 2023 14:11:39 +0000 Subject: [PATCH 9/9] Style code --- R/create_episode_file.R | 4 ---- 1 file changed, 4 deletions(-) diff --git a/R/create_episode_file.R b/R/create_episode_file.R index 233237585..12e8a1d7e 100644 --- a/R/create_episode_file.R +++ b/R/create_episode_file.R @@ -1,4 +1,3 @@ - #' Produce the Source Episode file #' #' @param processed_data_list containing data from processed extracts. @@ -116,7 +115,6 @@ create_episode_file <- function( correct_cij_vars() %>% fill_missing_cij_markers() %>% add_ppa_flag() %>% - link_delayed_discharge_eps(year, dd_data) %>% add_nsu_cohort(year, nsu_cohort) %>% match_on_ltcs(year, ltc_data) %>% @@ -146,8 +144,6 @@ create_episode_file <- function( } return(episode_file) - - } #' Store the unneeded episode file variables