From 282454296e1d79db3cc73b816502aa739a7662f7 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Mon, 20 May 2024 11:58:44 +0100 Subject: [PATCH] Add condition if CHI exists in data file --- 00_Sort_BI_Extracts.R | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/00_Sort_BI_Extracts.R b/00_Sort_BI_Extracts.R index 461374a58..e04a953a1 100644 --- a/00_Sort_BI_Extracts.R +++ b/00_Sort_BI_Extracts.R @@ -46,13 +46,17 @@ for (csv_file in csv_files) { # Read in each file and replace chi with anon_chi for (csv_file in csv_files) { - read_file(csv_file) %>% - dplyr::rename_with(~ paste0("chi"), tidyselect::contains("UPI")) %>% - slfhelper::get_anon_chi(chi = chi) %>% - readr::write_csv(file = new_file_path) + if (any(grepl("UPI", names(csv_file)))) { + read_file(csv_file) %>% + dplyr::rename_with(~ paste0("chi"), tidyselect::contains("UPI")) %>% + slfhelper::get_anon_chi(chi = chi) %>% + readr::write_csv(file = new_file_path) + } else { + fs::file_copy(csv_file, new_file_path, overwrite = TRUE) + } + + file.remove(csv_file) + cat("Replaced chi with anon chi:", csv_file, "to", new_file_path, "\n") } - - file.remove(csv_file) - cat("Replaced chi with anon chi:", csv_file, "to", new_file_path, "\n") } }