Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

see memory usage of the computer vs of memory usage of R in Rstudio?

Tags:

memory

r

rstudio

I know I can check the size of an R object using object.size, but how do I check the total memory usage of R, the memory composition in R - in Rstudio?

I saw this post, but didn't find a Memory usage button under the Tools menu.

I'm using Rstudio V 0.99.896 and R V 3.2.5.

Specific context:

I look at Windows Task Manager when working with R, and I notice the memory usage of the computer increased by ~7G when I read.table a ~2G data into R.

like image 912
YJZ Avatar asked May 03 '16 23:05

YJZ


2 Answers

Use gc() The help file says

The primary purpose of calling gc is for the report on memory usage.

My understanding is that the

  • second column "Used (MB)"
  • second row "VCells"

is the most important (human readable) number to check the total amount of memory that R is currently using. You can test this as follows in a fresh session:

gc(verbose=TRUE)
temp <- numeric(1e9)
gc(verbose=TRUE)

The remaining two (human readable) columns describe when automatic garbage collection is triggered and the maximum amount of memory that has been used in the current session.

like image 185
lmo Avatar answered Oct 02 '22 17:10

lmo


Check out pryr::mem_used().

This should tell you how much RAM all the objects in a particular R session are using.

This should work in RStudio as well as base R.

Here's some more details from Hadley:

http://adv-r.had.co.nz/memory.html#gc

like image 28
CephBirk Avatar answered Oct 02 '22 17:10

CephBirk