Forcing garbage collection to run in R with the gc() command

“Probably.” I do it too, and often even in a loop as in

cleanMem <- function(n=10) { for (i in 1:n) gc() }

Yet that does not, in my experience, restore memory to a pristine state.

So what I usually do is to keep the tasks at hand in script files and execute those using the ‘r’ frontend (on Unix, and from the ‘littler’ package). Rscript is an alternative on that other OS.

That workflow happens to agree with

which we covered here before.

Leave a Comment