Skip to content

Commit

Permalink
Add condition if CHI exists in data file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jennit07 committed May 20, 2024
1 parent 630d8d0 commit 291f4f8
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions 00_Sort_BI_Extracts.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit 291f4f8

Please sign in to comment.