Skip to content

Commit

Permalink
Clean up the environment after every iteration of the loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Moohan committed May 6, 2024
1 parent fe3d3ae commit bb77728
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ map <- paste0(lp_path, "Master RMarkdown Document & Render Code/Output/maps/", H

stopifnot(file.exists(map)) # Error if the file path doesn't exist.

loop_env <- ls()

# 2. Loop through each locality to create the main body of the profiles and the summary table
for (LOCALITY in locality_list) {
## 2a) Source in all the scripts for a given LOCALITY
Expand Down Expand Up @@ -97,4 +99,9 @@ for (LOCALITY in locality_list) {
output_file = paste0(LOCALITY, " - Summary Table.docx"),
output_dir = paste0(lp_path, "Master RMarkdown Document & Render Code/Output/Summary Tables/")
)

# Clean up the environment before starting the next loop
rm(list = setdiff(ls(), loop_env))
# Make sure memory is freed
gc()
}

0 comments on commit bb77728

Please sign in to comment.