Home > Software design >  R: What replaces memory.limit()?
R: What replaces memory.limit()?

Time:10-02

I recently updated to the latest R for Windows after a 3 year hiatus. I see that the memory.limit() function is now obsolete [for some reason; it always worked well for me]. As of now what is the preferred method for determining the amount of RAM, on a Windows 10 machine, from within R.

CodePudding user response:

You could invoke a invoke a system command.

system('wmic MEMORYCHIP get BankLabel, DeviceLocator, Capacity, Speed')
# BankLabel  Capacity    DeviceLocator  Speed  
# None       4160749568  M0                    
# None       4227858432  M1                    
# 
# [1] 0

Similarly on Linux.

system('free -h')
#                total        used        free      shared  buff/cache   available
# Mem:            31Gi       6.5Gi        17Gi       466Mi       6.9Gi        23Gi
# Swap:          2.0Gi          0B       2.0Gi

To store the values in an object, use intern=TRUE.

s <- system('free -h', intern=TRUE)
s
# [1] "               total        used        free      shared  buff/cache   available"
# [2] "Mem:            31Gi       5.9Gi        18Gi       332Mi       6.7Gi        24Gi"
# [3] "Swap:          2.0Gi          0B       2.0Gi"                                    

On Windows:

system('wmic MEMORYCHIP get BankLabel, DeviceLocator, Capacity, Speed', intern=TRUE)
  • Related