title: Error: C stack usage is too close to the limit
body: <p>I'm attempting to run some fairly deep recursive code in R and it keeps giving me this error:</p>
  
  <blockquote>
    <p>Error: C stack usage is too close to the limit </p>
  </blockquote>
  
  <p>My output from <code>CStack_info()</code> is:</p>
  
  <pre><code>Cstack_info()
      size    current  direction eval_depth 
  67108864       8120          1          2 
  </code></pre>
  
  <p>I have plenty of memory on my machine, I'm just trying to figure out how I can increase the CStack for R.</p>
  
  <p>EDIT: Someone asked for a reproducible example. Here's some basic sample code that causes the problem. Running f(1,1) a few times you'll get the error. Note that I've already set --max-ppsize = 500000 and options(expressions=500000) so if you don't set those you might get an error about one of those two things instead. As you can see, the recursion can go pretty deep here and I've got no idea how to get it to work consistently. Thanks.</p>
  
  <pre><code>f &lt;- function(root=1,lambda=1) {
      x &lt;- c(0,1);
      prob &lt;- c(1/(lambda+1),lambda/(lambda+1));
          repeat {
        if(root == 0) {
          break;
        }
        else {
          child &lt;- sample(x,2,replace=TRUE,prob);
          if(child[1] == 0 &amp;&amp; child[2] == 0) {
            break;
          }
          if(child[1] == 1) {
            child[1] &lt;- f(root=child[1],lambda);
          }
          if(child[2] == 1 &amp;&amp; child[1] == 0) {
            child[2] &lt;- f(root=child[2],lambda);
          }
        }
        if(child[1] == 0 &amp;&amp; child[2] == 0) {
          break;
        }
        if(child[1] == 1 || child[2] == 1) {
          root &lt;- sample(x,1,replace=TRUE,prob);
        }
          }
      return(root)
  }
  </code></pre>