Search code examples
rargumentsstartup

How can I get and change start arguments from the R session


I want to start R with arguments R --min-nsize=8000000 --min-vsize=2048M

min-nsize - This is the minimal number of 'nodes'. Each R object is a node, so a list of 1,000,000 strings will use up 1,000,000 nodes. We don't want to run out of nodes if we can avoid it.

min_vsize - The heap size (in either B, K, M, or G). Usually this limit it hit after the node limit, so it's worth experimenting with it.

Can I access those arguments from within the session (like with options()) and can I reset it within the session.


Solution

  • I doubt R will incorporate changes to those values once the session is started, but you could try changing the respective environment variables R_NSIZE and R_VSIZE.

    That said, you seem to misunderstand what these arguments do. They only set the initial values (and lower boundary) for triggering garbage collection. They don't have anything to do with "running out of nodes".

    If you're trying to control memory usage, you need to follow the advice in ?memory.limit:

    To restrict memory usage on a Unix-alike use the facilities of the shell used to launch R, e.g. 'limit' or 'ulimit'.

    If you're trying to control the garbage collector, the R_GC_MEM_GROW envrionment variable would probably be more useful. As it says in ?Memory:

    The strategy used for growth can be specified by setting the environment variable 'R_GC_MEM_GROW' to an integer value between 0 and 3. This variable is read at start-up. Higher values grow the heap more aggressively, thus reducing garbage collection time but using more memory.