Increase Memory in R

Sheeraz Gul Jan 30, 2023
  1. Increase Memory Manually in R
  2. Increase Memory by the memory.limit() Method in R
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.

    R Properties

  • Go to the Shortcut tab and find the Target field.

    R Properties Target 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 click OK.
    --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.

Author: Sheeraz Gul
Sheeraz Gul avatar Sheeraz Gul avatar

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

Related Article - R Memory