How can I get the current RAM usage in R? Ideally, it would work for both Unix and Windows platforms. In windows I used following code:
total_mem<-system("wmic ComputerSystem get TotalPhysicalMemory", intern = TRUE)
total_mem<-as.numeric(gsub("\\D", "", total_mem[2]))
total_mem<-total_mem/1000
free_mem<-system("wmic OS get FreePhysicalMemory", intern = TRUE)
free_mem<-as.numeric(gsub("\\D", "", free_mem[2]))
used_mem<-total_mem-free_mem
percentage_used_mem<-1-free_mem/total_mem
Is there a better way to get the current RAM usage, such that works with both Unix and Windows platforms.
According to how to get current cpu and ram usage in python? and the "reticulate" package:
library(reticulate)
aa<-reticulate::import("psutil")
mem_percent=aa$virtual_memory()$percent
But this way needs Python to be installed on the platform.