From 0746ee6e1235e641a10d9d736a2138e8b7285879 Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Fri, 23 Aug 2024 15:51:45 +0100 Subject: [PATCH] update write_tests_xlsx --- R/process_tests_episode_file.R | 2 +- R/process_tests_individual_file.R | 2 +- R/write_tests_xlsx.R | 47 +++++++++++++++++++++++-------- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/R/process_tests_episode_file.R b/R/process_tests_episode_file.R index ccf8e495c..289b43686 100644 --- a/R/process_tests_episode_file.R +++ b/R/process_tests_episode_file.R @@ -31,7 +31,7 @@ process_tests_episode_file <- function(data, year) { recid = TRUE ) %>% dplyr::arrange(.data[["recid"]]) %>% - write_tests_xlsx(sheet_name = "ep_file", year, workbook_name = "ep_file") + write_tests_xlsx(sheet_name = stringr::str_glue({"ep_file_{year}"}), workbook_name = "ep_file") return(comparison) } diff --git a/R/process_tests_individual_file.R b/R/process_tests_individual_file.R index 9643a4f3f..4283ec029 100644 --- a/R/process_tests_individual_file.R +++ b/R/process_tests_individual_file.R @@ -34,7 +34,7 @@ process_tests_individual_file <- function(data, year) { old_data = produce_individual_file_tests(old_data), new_data = produce_individual_file_tests(data) ) %>% - write_tests_xlsx(sheet_name = "indiv_file", year, workbook_name = "indiv_file") + write_tests_xlsx(sheet_name = stringr::str_glue({"indiv_file_{year}"}), workbook_name = "indiv_file") return(comparison) } diff --git a/R/write_tests_xlsx.R b/R/write_tests_xlsx.R index ec3cc5705..a924d51de 100644 --- a/R/write_tests_xlsx.R +++ b/R/write_tests_xlsx.R @@ -24,17 +24,42 @@ write_tests_xlsx <- function(comparison_data, "cross_year" )) { # Set up the workbook ---- - tests_workbook_name <- dplyr::case_when( - is.null(year) & workbook_name == "ep_file" ~ stringr::str_glue(latest_update(), "_ep_file_tests"), - !is.null(year) & workbook_name == "ep_file" ~ stringr::str_glue(latest_update(), "_{year}_ep_file_tests"), - is.null(year) & workbook_name == "indiv_file" ~ stringr::str_glue(latest_update(), "_indiv_file_tests"), - !is.null(year) & workbook_name == "indiv_file" ~ stringr::str_glue(latest_update(), "_{year}_indiv_file_tests"), - is.null(year) & workbook_name == "lookup" ~ stringr::str_glue(latest_update(), "_lookups_tests"), - is.null(year) & workbook_name == "sandpit" ~ stringr::str_glue(latest_update(), "_sandpit_extract_tests"), - is.null(year) & workbook_name == "cross_year" ~ stringr::str_glue(latest_update(), "_cross_year_tests"), - !is.null(year) & workbook_name == "sandpit" ~ stringr::str_glue(latest_update(), "_sandpit_extract_tests"), - !is.null(year) & workbook_name == "extract" ~ stringr::str_glue(latest_update(), "_{year}_extract_tests") - ) + if (workbook_name == "ep_file") { + if (is.null(year)) { + tests_workbook_name <- + stringr::str_glue(latest_update(), "_ep_file_tests") + } + } + if (workbook_name == "indiv_file") { + if (is.null(year)) { + tests_workbook_name <- + stringr::str_glue(latest_update(), "_indiv_file_tests") + } + } + if (workbook_name == "lookup") { + if (is.null(year)) { + tests_workbook_name <- + stringr::str_glue(latest_update(), "_lookups_tests") + } + } + if (workbook_name == "sandpit") { + tests_workbook_name <- + stringr::str_glue(latest_update(), "_sandpit_extract_tests") + } + if (workbook_name == "cross_year") { + if (is.null(year)) { + tests_workbook_name <- + stringr::str_glue(latest_update(), "_cross_year_tests") + } + } + if (workbook_name == "extract") { + if (is.null(year)) { + } else{ + tests_workbook_name <- + stringr::str_glue(latest_update(), "_{year}_extract_tests") + } + } + tests_workbook_path <- fs::path( get_slf_dir(),