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") } }