Tricks to manage the available memory in an R session

前端 未结 27 1357
情深已故
情深已故 2020-11-22 01:23

What tricks do people use to manage the available memory of an interactive R session? I use the functions below [based on postings by Petr Pikal and David Hinds to the r-he

27条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 01:48

    I really appreciate some of the answers above, following @hadley and @Dirk that suggest closing R and issuing source and using command line I come up with a solution that worked very well for me. I had to deal with hundreds of mass spectras, each occupies around 20 Mb of memory so I used two R scripts, as follows:

    First a wrapper:

    #!/usr/bin/Rscript --vanilla --default-packages=utils
    
    for(l in 1:length(fdir)) {
    
       for(k in 1:length(fds)) {
         system(paste("Rscript runConsensus.r", l, k))
       }
    }
    

    with this script I basically control what my main script do runConsensus.r, and I write the data answer for the output. With this, each time the wrapper calls the script it seems the R is reopened and the memory is freed.

    Hope it helps.

提交回复
热议问题