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

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.


Using pryr library:

library("pryr")

mem_used()
# 27.9 MB

x <- mem_used()
x
# 27.9 MB
class(x)
# [1] "bytes"

Result is the same as @RHertel's answer, with pryr we can assign the result into a variable.

system('grep MemTotal /proc/meminfo')
# MemTotal:       263844272 kB

To assign to a variable with system call, use intern = TRUE:

x <- system('grep MemTotal /proc/meminfo', intern = TRUE)
x
# [1] "MemTotal:       263844272 kB"
class(x)
# [1] "character"

Tags:

Linux

Memory

R