Do you need a way to find out which individual variables in R consume the most memory?
# create dummy variables for demonstration
x <- 1:1000
y <- 1:10000
z <- 1:100000
# print aggregate memory usage statistics
print(paste('R is using', memory.size(), 'MB out of limit', memory.limit(), 'MB'))
# create function to return matrix of memory consumption
object.sizes <- function()
{
return(rev(sort(sapply(ls(envir=.GlobalEnv), function (object.name)
object.size(get(object.name))))))
}
# print to console in table format
object.sizes()
# draw bar plot
barplot(object.sizes(),
main="Memory usage by object", ylab="Bytes", xlab="Variable name",
col=heat.colors(length(object.sizes())))
# draw dot chart
dotchart(object.sizes(), main="Memory usage by object", xlab="Bytes")
# draw pie chart
pie(object.sizes(), main="Memory usage by object")
While trying to fit models to a large data set (using ctree and cforest in the party package), I kept running out of memory. I was surprised to learn the model—which contains just rules, right?—consumes much more memory than the original input data frame.
Using the memory.limit() function I increased R’s memory limit from 1500MB to 2000MB, but too bad 32-bit Windows inherently has a small memory limit.
I found the following links helpful related to R memory usage:
- R FAQ: There seems to be a memory limit
- How can I examine and control memory usage in R in Windows?
- Data mining survivor: Memory Usage

Pingback: Od Informacji do Wiedzy » Archiwum bloga » R stronki
Thanks. It works!