3

I'm currently running some queries to a database and getting back some big files as a result. I have encountered the common problem of Windows not freeing the memory, even though I 'rm()' everything and (edit) calling 'gc()'. One workaround i have found is using .rs.restartR() in Rstudio.

This though requires me to constantly watch my script, in order to continue it after the session restart. Is it possible to automate it? If not what other methods do people use to overcome this problem?

Stelios K.
  • 313
  • 4
  • 14
  • 2
    `rm()` doesn't necessarily free the memory. You can also use `gc()` after `rm()` though. – Hack-R Jun 15 '16 at 17:36
  • Did you ever figure out a way to automate this as @Hack-R mentioned below, or some other way that worked for you? – Jon Dec 07 '20 at 15:10
  • 1
    Yes, by using bat files you can achieve the sequence described by Hack-R. Refer to https://stackoverflow.com/questions/6788928/how-to-run-a-r-language-r-file-using-batch-file – Stelios K. Dec 09 '20 at 11:17

1 Answers1

1

You could break the code into 2 files and write a batch file (.bat) that runs the first file through .rs.restartR() and then the remainder of the code in the next file.

You could also skip the .bat and just schedule both .R scripts to run in Task Scheduler.

Also, please see my comment regarding garbage collection (gc()).

Hack-R
  • 22,422
  • 14
  • 75
  • 131