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

Viewed 19734

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?

3 Answers

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"

Yes, memory.size() and memory.limit() is not working in linux/unix. I can suggest unix package.

To increase the memory limit in linux:

install.packages("unix") 
library(unix)
rlimit_as(1e12)  #increases to ~12GB

You can also check the memory with this:

rlimit_all()

for detailed information: https://rdrr.io/cran/unix/man/rlimit.html

also you can find further info here: limiting memory usage in R under linux

Related