After running several models I need to run a system()
command on my R script to shutdown my EC2 instance, but when I get to that point I get:
ca
I'm just posting this because it's too long to fit in the comments. Since you haven't included any code, it's pretty hard to give advice. But, here is some code that maybe you can think about.
wd <- getwd()
assign('.First', function(x) {
require('plyr') #and whatever other packages you're using
file.remove(".RData") #already been loaded
rm(".Last", pos=.GlobalEnv) #otherwise won't be able to quit R without it restarting
setwd(wd)
}, pos=.GlobalEnv)
assign(".Last", function() {
system("R --no-site-file --no-init-file --quiet")
}, pos=.GlobalEnv)
save.image() #or only save the things you want to be reloaded.
q("no")
The idea is that you save the things you need in a file called .RData
. You create a .Last
function that will be run when you quit R. The .Last
function will start a new session of R. And you create a .First
function that will be run as soon as R is restarted. The .First
function will load packages you need and clean up.
Now, you can quit R and it will restart loading the things you need.
(q("no")
means don't save, but you already saved everything you need in .RData
which will be loaded when it restarts)