R Cannot allocate memory though memory seems to be available

前端 未结 1 1923
悲哀的现实
悲哀的现实 2020-12-10 04:54

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         


        
1条回答
  •  醉梦人生
    2020-12-10 05:40

    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)

    0 讨论(0)
提交回复
热议问题