mem | R Documentation |
See a list of the largest objects in memory, and how much RAM they are using up
Uses object.size()
to return info on memory consumption for largest n objects
mem(n = 10, env = .GlobalEnv)
n |
Numeric, default is 10. How many objects to show (e.g., top 10) |
env |
The environment to check, defaulting to .GlobalEnv but could be something like env = as.environment(3) or 3 |
prints a list of objects and their sizes
## Not run:
mem()
mem(15)
mem(env = 2)
# draw bar plot
y = mem()
barplot(y,
main="Memory usage by object", ylab="Bytes", xlab="Variable name",
col=heat.colors(length(y)))
# draw pie chart again
pie(mem(), main = "Memory usage by object")
################################## #
# memory.size() and memory.limit() and object.sizes() comparison:
################################## #
memory.size() to print aggregate memory usage statistics
print(paste('R is using', memory.size(), 'MB out of limit', memory.limit(), 'MB'))
# object.sizes() to see memory total used by objects:
# NOTE: THIS DOES NOT MATCH TOTAL GIVEN BY memory.size();
# it is only about half as much in the case I tried:
sum(as.numeric(object.sizes()))
# same, in MEGABYTES:
unclass(sum(as.numeric(object.sizes())))/1e6
# print to console in table format
object.sizes()
# see a list of the top few variables:
head(cbind(object.sizes()))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.