I would like to increase (or decrease) the amount of memory available to R. What are the methods for achieving this?
7 Answers
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)
.

- 81,064
- 34
- 182
- 193

- 28,337
- 7
- 52
- 74
-
8Note that on 32-bit Windows, R can only use up to 3Gb of RAM, regardless of how much you have installed. There is a 64-bit version of R for Windows available from REvolution Computing, which runs on 64-bit Windows and can use all the RAM available: http://www.revolution-computing.com/products/revolution-enterprise.php – David Smith Sep 08 '09 at 17:40
-
6Just two notes: (i) memory.limit() only works on Windows, and (ii) the command that will return the proper answer is round(memory.limit(),2) -- at least on my version of R (2.8.1). – medriscoll Sep 08 '09 at 18:01
-
38Any suggestion on how to get similar information as memory.limit() working on linux? – exl Oct 13 '12 at 02:10
-
5The webpage doesn't exist anymore. It's hard for me to follow this without the images. I don't see a "Shortcut" tab for example. Also, can you use this to decrease the max memory? – blakeoft Mar 23 '15 at 20:31
-
6So, what about mac users? Can we do something about it? – Alfredo Lozano Nov 30 '15 at 22:49
-
Using `memory.limit` also helped me to allow larger single objects (the limit for which seemed to be less than the total limit). My total limit was at the default of about 3GB and I was told that I couldn't assign a vector greater than 1.6GB. However, after putting `memory.limit(10000)` (in MB), assigning the vector (a 5-d array actually) was no longer a problem. – CJB Dec 10 '15 at 09:35
-
1sorry this doesn't work. When trying to change the target field, it says that the field is not valid. – Gabriel123 Sep 07 '17 at 14:52
-
The link to the website this is copied from no longer works. Where is says '500M' - that means 500 what? Million, or megabytes? I have 16GB of RAM so am wondering what is the biggest number I could put in here? – Jamie Feb 04 '22 at 14:52
-
`Warning message: 'memory.limit()' is no longer supported` – Paul Schmidt Dec 07 '22 at 08:35
-
`Warning: unknown option --max-mem-size=5000M` – Tomas Jan 09 '23 at 23:53
Use memory.limit()
. You can increase the default using this command, memory.limit(size=2500)
, where the size is in MB. You need to be using 64-bit in order to take real advantage of this.
One other suggestion is to use memory efficient objects wherever possible: for instance, use a matrix instead of a data.frame.
-
3I don't really understand how this works. I ran into this memory limit issue and received the error "Reached total allocation of 8182Mb". I'm using 64-bit with 8GB ram so I seemed to be SOL. However, for shiggles, I set memory.limit(size=50000)...AND IT WORKED! But why??? – theforestecologist Dec 16 '15 at 17:52
-
2I know this is 7 years old, but I'm trying to reduce the amount of RAM that can be used by R but whenever I try to reduce the value I get this message (I have 12gb Ram on a 64-bit Windows machine). Warning message: In memory.limit(4095) : cannot decrease memory limit: ignored – hellter Jun 12 '16 at 18:32
For linux/unix, I can suggest unix package.
To increase the memory limit in linux:
install.packages("unix")
library(unix)
rlimit_as(1e12) #increases to ~12GB
You can also check the memory with this:
rlimit_all()
for detailed information: https://rdrr.io/cran/unix/man/rlimit.html
also you can find further info here: limiting memory usage in R under linux

- 419
- 5
- 7
Microsoft Windows accepts any memory request from processes if it could be done.
There is no limit for the memory that can be provided to a process, except the Virtual Memory Size.
Virtual Memory Size is 4GB in 32bit systems for any processes, no matter how many applications you are running. Any processes can allocate up to 4GB memory in 32bit systems.
In practice, Windows automatically allocates some parts of allocated memory from RAM or page-file depending on processes requests and paging file mechanism.
But another limit is the size of paging file. If you have a small paging-file, you cannot allocated large memories. You could increase the size of paging file according to Microsoft to have more memory space.

- 2,332
- 6
- 33
- 59
- Buy more ram
- Switch to a 64-bit OS. Combine with point 1.

- 1,875
- 4
- 17
- 23

- 360,940
- 56
- 644
- 725
-
28Buy more ram (and switch to other OS) is not general appropriate solution. – om-nom-nom Apr 13 '12 at 15:21
-
18Sure it is, just like working on smaller problems that are appropriate for the problem at hand. Wishing for a solution usually doesn't get you one either. – Dirk Eddelbuettel Apr 13 '12 at 15:29
To increase the amount of memory allocated to R you can use memory.limit
memory.limit(size = ...)
Or
memory.size(max = ...)
About the arguments
- size - numeric. If NA report the memory limit, otherwise request a new limit, in Mb. Only values of up to 4095 are allowed on 32-bit R builds, but see ‘Details’.
- max - logical. If TRUE the maximum amount of memory obtained from the OS is reported, if FALSE the amount currently in use, if NA the memory limit.

- 14,289
- 18
- 86
- 145
In RStudio, to increase:
file.edit(file.path("~", ".Rprofile"))
then in .Rprofile type this and save
invisible(utils::memory.limit(size = 60000))
To decrease: open .Rprofile
invisible(utils::memory.limit(size = 30000))
save and restart RStudio.

- 131
- 3