Increasing (or decreasing) the memory available to R processes
From:
http://gking.harvard.edu/zelig/docs/How_do_I2.html (mirror)
Windows users may get the error that R
has run out of memory.If you have R already installed and
subsequently install more RAM, you may
have to reinstall R in order to take
advantage of the additional capacity.You may also set the amount of
available memory manually. Close R,
then right-click on your R program
icon (the icon on your desktop or in
your programs directory). Select
``Properties'', and then select the
``Shortcut'' tab. Look for the
``Target'' field and after the closing
quotes around the location of the R
executible, add--max-mem-size=500M
as shown in the figure below. You may
increase this value up to 2GB or the
maximum amount of physical RAM you
have installed.If you get the error that R cannot
allocate a vector of length x, close
out of R and add the following line to
the ``Target'' field:--max-vsize=500M
or as appropriate. You can always
check to see how much memory R has
available by typing at the R prompt
memory.limit()
which gives you the amount of available memory in MB. In previous versions of R you needed to use: round(memory.limit()/2^20, 2)
.
Memory.limit vs memory.size in R
In a nutshell:
memory.size
is the memory in use by R
.
memory.limit
is the total amount of memory available to R
. If only a set amount is allocated, one can use the limit
argument to increase the memory size (if possible given system/OS constraints).
These only work on Windows, to be clear.
Tricks to manage the available memory in an R session
To further illustrate the common strategy of frequent restarts, we can use littler which allows us to run simple expressions directly from the command-line. Here is an example I sometimes use to time different BLAS for a simple crossprod.
r -e'N<-3*10^3; M<-matrix(rnorm(N*N),ncol=N); print(system.time(crossprod(M)))'
Likewise,
r -lMatrix -e'example(spMatrix)'
loads the Matrix package (via the --packages | -l switch) and runs the examples of the spMatrix function. As r always starts 'fresh', this method is also a good test during package development.
Last but not least r also work great for automated batch mode in scripts using the '#!/usr/bin/r' shebang-header. Rscript is an alternative where littler is unavailable (e.g. on Windows).
Related Topics
How to Use "≪≪-" (Scoping Assignment) in R
Getting the Top Values by Group
Elegant Way to Check For Missing Packages and Install Them
How to Do Vlookup and Fill Down (Like in Excel) in R
What Does "The Following Object Is Masked from 'Package:Xxx'" Mean
Extracting Specific Columns from a Data Frame
What Exactly Is Copy-On-Modify Semantics in R, and Where Is the Canonical Source
Create Counter With Multiple Variables
How to Drop Columns by Name in a Data Frame
How to Read Multiple .Txt Files into R
Plot Multiple Columns on the Same Graph in R
Is There an R Function For Finding the Index of an Element in a Vector
Plot a Legend Outside of the Plotting Area in Base Graphics
Cannot Install R-Forge Package Using Install.Packages
Split String Column to Create New Binary Columns
Ggplot Does Not Work If It Is Inside a For Loop Although It Works Outside of It
Why Does Summarize or Mutate Not Work With Group_By When I Load 'Plyr' After 'Dplyr'