0

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.

Masoud
  • 535
  • 3
  • 19
  • are you looking for the garbage cleaner `gc()`? – D.J Nov 15 '22 at 06:54
  • @D.J, Can I get the current RAM usage(total, percent) with gc()? – Masoud Nov 15 '22 at 06:58
  • i don't think so - i thought you wanted to know R's ram useage. there is a way to [check](https://support.posit.co/hc/en-us/articles/1500005616261-Understanding-Memory-Usage-in-the-RStudio-IDE) with rstudio (total ram) but i don't know how to replicate it – D.J Nov 15 '22 at 07:54

0 Answers0