Increase Memory in R

Sometimes R users get the out-of-memory error; to solve that, we can increase the memory in R. This tutorial demonstrates how to increase the memory in R.
There are two methods to increase the memory in R; one is manual, and the other is a method.
Increase Memory Manually in R
Windows users mostly get out-of-memory errors. We can increase the memory of R from the properties of the R program or app.
Follow the steps below if you are using Windows.
-
Right-click on the R program icon from the desktop or the program directory and go to
Properties
. -
Go to the
Shortcut
tab and find theTarget
field. -
Add the following line into the
Target
field.--max-mem-size=1000M
-
The code above will allocate 1000 MB of memory to the R program; the maximum can be the memory up to the memory of R.
-
Finally, click
OK
, and you are good to go. -
There might be an error that R cannot allocate the vector of length. Then add the following line to the
Target
field and clickOK
.--max-vsize=1000M
Increase Memory by the memory.limit()
Method in R
memory.limit()
can allocate memory to an R program. It takes one parameter size
in MBs.
Let’s try an example.
memory.limit(size=1000)
The code above will allocate the 1000 MB memory to the R program.
Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.
LinkedIn Facebook