I have a "Master R script" that runs multiple R scripts using "source()". It looks something like this:
source("script1.R")
source("script2.R")
source("script3.R")
source("script4.R")
source("script5.R")
source("script6.R")
source("script7.R")
source("script8.R")
Scripts 1 to 8 need to run sequentially. This "Master R script" is scheduled using cron and "Rscript" command.
Rscript --verbose --vanilla "master_r_script.R"
My "Master R script" throws an error='Cannot allocate memory' after running a few R scripts. I've tried calling rm(list = ls()) and gc(verbose = TRUE, reset = TRUE) after every source() command, but that still doesn't solve the problem.
I need a way that somehow "cleans" the R environment and frees up the memory. I could of course break up the "Master R script" into multiple "RScript calls" but I want to avoid doing that.
How can I "restart" a session created by an "Rscript". The solutions here are not applicable because they're restarting an R REPL session.