Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to R's `memory.size()` in linux?

Tags:

linux

memory

r

R's memory.size() is a Windows only. For other functions (such as windows()) the help page gives pointer to non-windows counterparts.

But for memory.size() I could find no such pointers.

So here is my question: is there a function to do the same as memory.size() but in linux?

like image 428
user189035 Avatar asked Mar 18 '16 08:03

user189035


1 Answers

I think that this should be handled by the operating system. There is no built-in limit that I know of; if necessary, R will use all the memory that it can get.

To obtain information on the total and/or on the available memory in linux, you can try

system('grep MemTotal /proc/meminfo')

or

system('free -m')

or

system('lshw -class memory')

The last command will complain that you should run this as super-user and it will give a warning that the output may not be accurate; but from my experience it will still provide a fairly useful output.


To obtain information on the memory usage of a running R script one could either monitor the currently used resources by starting top in a separate terminal, or use, e.g., the following system call from within the R script:

system(paste0("cat /proc/",Sys.getpid(),"/status | grep VmSize"))

Hope this helps.

like image 142
RHertel Avatar answered Oct 19 '22 17:10

RHertel