2

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.

Chris
  • 2,256
  • 1
  • 19
  • 41

1 Answers1

1

On Linux / MAC OSX:

installed.RAM <- as.numeric(system("awk '/MemTotal/ {print $2}' /proc/meminfo",intern=TRUE));
used.RAM <- installed.RAM - as.numeric(system("awk '/MemFree/ {print $2}' /proc/meminfo", intern=TRUE));
rinni
  • 2,246
  • 1
  • 18
  • 21