Re: [R] Error: C stack usage is too close to the limit

From: Maarten Blaauw <>
Date: Sun, 27 Jan 2008 00:55:14 +0100

Sorry, indeed I forgot to put some of the factors in the code. Here it is again, now updated:

calcurve <- cbind(1:2e4, 1:2e4, rep(100, length=2e4));

caldist <- function(cage, error, sdev=2, times=5, By=1)   {
   calcurve <- calcurve[which((calcurve[,2]+calcurve[,3]) >= cage-(times*error)),];

   calcurve <- calcurve[which((calcurve[,2]-calcurve[,3]) <= cage+(times*error)),];

   theta <- seq(min(calcurve[,1]), max(calcurve[,1]), by=By);

   interpolate <- function(th, col)

     if(th==calcurve[1,1]) {calcurve[1,col]}else
     if(th==calcurve[nrow(calcurve),1]) {calcurve[nrow(calcurve),col]}else
       k <- min(which(calcurve[,1] > th));
       slope <-  
       calcurve[k-1,col] + slope*(th-calcurve[k-1,1]);


   mu <- c();
   cerror <- c();
   for(i in 1:length(theta))

     mu[i] <- interpolate(theta[i],2);
     cerror[i] <- interpolate(theta[i],3);

   caldist <- dnorm(mu, cage, (error^2+cerror^2)^.5);    cbind(theta, caldist/sum(caldist));


Strangely enough the stacking error message seems not to happen every time. It also has happened on the WinXP partition of the same Toshiba laptop. So it is not as reproducible as I first hoped/feared.

Dr. Maarten Blaauw
School of Geography, Archaeology & Palaeoecology
Queen's University Belfast, U.K.
On leave from Department of Earth Sciences
Uppsala University, Sweden

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 26 Jan 2008 - 23:58:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 27 Jan 2008 - 00:30:09 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive