[R] Please Help_Error:cannot allocate vector of size 400.4Mb

Peter Langfelder peter.langfelder at gmail.com
Tue Sep 21 20:39:38 CEST 2010


On Tue, Sep 21, 2010 at 9:50 AM, qcshare <qcshare at gmail.com> wrote:
>
> Hello, everyone,
> When I run R, I met:
> "error:cannot allocate vector of size 400Mb", My data is large.
> What should I do?
> Thanks, everyone.
>

How big is the RAM in your computer?

There are a few things you can try:

1. Before running the analysis, shut down all other programs. Before
you execute the analysis in R, issue garbage collection (call the
function gc(), perhaps a few times).

2. If that doesn't help, try restarting your computer, not opening any
applications except R, and follow point 1.

3. If 2. doesn't work, the next best step is to increase the amount of
RAM, assuming your system and R can actually use it (e.g., 32 bit
systems and R can typically only use 2-3 GB of memory - if you already
have that much in your computer, adding more will not help).

4. If you can't get a bigger computer, try doing the analysis more
cleverly. Often a large calculation can be split into smaller chunks
with a small penalty in terms of performance or perhaps accuracy. If
you can modify the code, try inserting garbage collection and/or
modify the code to minimize the number of large objects held in
memory. Knowing what is it you are trying to do would help.

5. If the analysis cannot be split into smaller chunks, the last
resort is to only use it on a subset of data. You lose some
accuracy/power/whatever, but it is better than having no results.

6. If you are a good Fortran or C programmer, and the analysis is
relatively simple (or simple to code), the last last resort is to code
the analysis in a compiled language where you may have better control
over memory allocation and usage. You can write the analysis in say
Fortran, compile it into a shared (dynamic-link) library, load the
library into R and call the compiled code from R. However, all this is
quite involved and should really be done as the last last resort if
all else fails.

Peter



More information about the R-help mailing list