I'm troubleshooting why my R-script uses too much RAM, and need to find where it occurs so I can start looking for a solution. The problem is that whenever the RAM is exceeded, the computer starts to swap to disk followed by 20 minutes of frustrating computer-freezings, R-restart, and need for reloading everything.
Can I make the script stop before the RAM is full? I suppose a code like this is what I need. But I can't figure out the "not sure 1" and "not sure 2" functions needed to get the actual situation.
installed.RAM <- notsure1()
used.RAM <- notsure2()
stopifnot(used.RAM < 0.9*installed.RAM)
What could notsure1() and notsure2() be?
I use R on Ubuntu (with RStudio Server). 16GB of RAM.