Error: C stack usage is too close to the limit

The stack size is an operating system parameter, adjustable per-process (see setrlimit(2)). You can’t adjust it from within R as far as I can tell, but you can adjust it from the shell before starting R, with the ulimit command. It works like this:

$ ulimit -s # print default
8192
$ R --slave -e 'Cstack_info()["size"]'
   size 
8388608

8388608 = 1024 * 8192; R is printing the same value as ulimit -s, but in bytes instead of kilobytes.

$ ulimit -s 16384 # enlarge stack limit to 16 megs
$ R --slave -e 'Cstack_info()["size"]'
    size 
16777216 

To make a permanent adjustment to this setting, add the ulimit command to your shell startup file, so it’s executed every time you log in. I can’t give more specific directions than that, because it depends on exactly which shell you have and stuff. I also don’t know how to do it for logging into a graphical environment (which will be relevant if you’re not running R inside a terminal window).

Leave a Comment