Full session size R

Due to the fact that I constantly reached the limit of memory in my R session (8 GB Windows PC), I start with remove to load large objects. However, as soon as I reached this limit, deleting objects seems to be inoperative.

So, I was wondering if there is a way to get the session size R. I know that you can get the size of the objects (saw in this thread ). I want to know if there is a way to calculate the total size of an R session (downloaded packages, objects, etc.).

Thanks!

+5
source share
2 answers

I personally use this function to get available memory:

 getAvailMem <- function(format = TRUE) { gc() if (Sys.info()[["sysname"]] == "Windows") { memfree <- 1024^2 * (utils::memory.limit() - utils::memory.size()) } else { # http://stackoverflow.com/a/6457769/6103040 memfree <- 1024 * as.numeric( system("awk '/MemFree/ {print $2}' /proc/meminfo", intern = TRUE)) } `if`(format, format(structure(memfree, class = "object_size"), units = "auto"), memfree) } 
+4
source

To get the shared memory used by R, you can try mem_used() from the pryr package. Unlike memory.size , this is OS independent because the R gc() function is used underneath. Try looking at the body of the function, as well as at pryr:::node_size and pryr:::show_bytes

 pryr::mem_used() 

Help file ?pryr::mem_used describes

R interrupts the memory usage in Vcell (memory used by vectors) and Ncells (memory used by everyone else). However, neither these differences nor the columns "gc trigger" and "max used" are usually important. Usually we are most interested in the first column: shared memory usage. This function wraps itself around gc () to return the total amount of memory (in megabytes) currently used by R.

You can also use pryr::mem_change to track the size of memory used by the R code. Try the example on the documentation page.

Numbers such as 28L and 56L , used to indicate the size of a node with pryr:::node_size , come from the help file ?gc , which describes

gc returns a matrix with the lines "Ncells" (cons cells), usually 28 bytes each of 32-bit systems and 56 bytes in 64-bit systems and "Vcells", (vector cells, 8 bytes each),

After deleting a large object, run gc() in free memory

+2
source

Source: https://habr.com/ru/post/1272531/


All Articles