How to limit the size of the memory RStudio uses during a process run?

r
rstudio

#1

Hello,

I want to limit the size of the memory used by RStudio on my laptop. It happens frequently that during a randomForest loop run or some other complex for loop runs, my system freezes as it is and whole of my memory is used up by RStudio.
Is there a way to limit the memory usage by RStudio?

Thanks!


#2

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()


#3

Hi I usually use this “-Xmx4g”

at the starting of the code where 4g stands for 4GB


#4

This is my target location - "C:\Program Files\R\R-3.2.3\bin\x64\Rgui.exe"
This is I want to add - --max-vsize=500M
Could you please show me how would i add this. ? Because When I add it says “Its not valid”.
Please Help.


#5

You can basically use the package “h2o” for memory allocation.Even you can fix the usage of #cores as well.After installing “h2o” you can check with ?h2o.init.
For better documentations you can visit these sites,
http://h2o-release.s3.amazonaws.com/h2o/rel-lambert/5/docs-website/Ruser/rtutorial.html


#6

Also @adityashrm21

While adding more hardware is always the easy solution, try to see whether you can tweak the random forest parameters
Number of Trees
Number of Features
etc etc

If you have a dataset of a million rows, it will not be a good idea to run a random forest on the set on your home PC. These are supposed to be resource intensive methodologies. If you can separate them into smaller subsets based on a particular column, the precision will also increase

Hope this helps

Anant