Skip to content

Memory Size & Allocation in R

3 messages · Brigid Mooney, jim holtman, Elizabeth Purdom

#
Try writing out the dataframe in smaller pieces.  If you have 800K row
and 18 columns, then this is about 14M items and if you have 8 bytes
per items (assuming all numeric; more for character), this is 115MB of
space that would probably be required to construct the output data (or
more).  Your error might be due to someplace along the line of getting
the memory, it was too fragmented to get the space required.  Try
writing out 20% at a time and appending to the file, or using a
connection.
On Tue, Jan 13, 2009 at 12:24 PM, Brigid Mooney <bkmooney at gmail.com> wrote:

  
    
#
Hi Brigid,

You will probably get some more informed answers in a bit, but to give 
you some quick things to try...

There's no size limit to an object like you are referring to. When 
you're having problems with small objects or simple operations, it 
sounds like you've used up the memory for running R. Try running gc() to 
get memory usage information -- what you're looking at may be static (I 
forget) giving the upper limits, rather than what you are actually using.

You may have an object that is too large or the accumulation of objects 
is too large. You can do object.size() to find it, or to look at all of 
your objects in your environment (sorted by size):

sort( sapply(ls(),function(x){object.size(get(x))}))

If you remove a large object (using rm()), call gc() again to flush out 
the memory (and see your improvement).

On the other hand, manipulating *very* large objects requires a lot of 
memory, as does some expensive operations of course, so if you are 
running into problems only when you are handling that object or running 
a certain program, it may be that you don't have enough memory on your 
computer for that task.

I also find that there are memory leaks when I use R in Windows for a 
long time. If I shut down R and start up again, especially after very 
memory intensive tasks, I often have a good bit more memory when I start 
back up.

Best,
Elizabeth
Brigid Mooney wrote: