Looping over many fits fills hard drive

Thanks for your response @Shauna_Sweet. I tried removing the stored objects and the double gc() at the end of each iteration, but it wasn’t able to clean up the residual Rtmp directories filling up my hard drive.

I then stumbled across unlink(), which can delete files and folders from R. The last lines inside my loop now look like this:

rm(sim_dat, sim_obs, stan_dat, fit, pred, stan_dat, MO_pred)
gc()
unlink(file.path("C:/Users/j.sweeney/AppData/Local/Temp", "Rtmp*"), recursive = T)

The recursive = T is a necessary argument. It feels like I’m throwing the kitchen sink at this problem, but it does the trick.

2 Likes