I'd like to work out how much RAM is being used by each of my objects inside my current workspace. Is there an easy way to do this?
+5
A:
You could try the lsos()
function from this question:
R> a <- rnorm(100)
R> b <- LETTERS
R> lsos()
Type Size Rows Columns
b character 1496 26 NA
a numeric 840 100 NA
R>
Dirk Eddelbuettel
2009-09-08 17:50:51
+2
A:
1. By Object
To get memory allocation on an object-by-object basis, use 'object.size'
object.size("how_much_RAM_am_i_using")
if 'how_much_RAM_am_i_using' is a variable name, then omit the quotes, or enclose the variable quoted variable name in a 'get' call
You can loop through your namespace:
for (itm in ls()){print(formatC(c(itm, object.size(get(itm))), format="d",
big.mark=",", width=30), quote=F)}
2. By Object Type
To get memory usage for your namespace by object type, use 'memory.profile'
memory.profile()
NULL symbol pairlist closure environment promise language
1 9434 183964 4125 1359 6963 49425
special builtin char logical integer double complex
173 1562 20652 7383 13212 4137 1
There's another function, 'memory.size()' but it only seems to work on Windows; it just returns a value in MB. To get the maximum amount of memory used at any time in the session, use memory.size(max=T).
doug
2010-01-08 00:15:07