错误:C堆栈使用率太接近极限
我试图在R中运行一些相当深的递归代码,它不断给我这个错误:
错误:C堆栈使用率太接近极限
我的输出CStack_info()是:
Cstack_info() size current direction eval_depth 67108864 8120 1 2
我的机器上有足够的内存,我只想弄清楚如何增加R的CStack。
编辑:有人要求一个可重复的例子。这是导致问题的一些基本示例代码。运行f(1,1)几次就会出现错误。请注意,我已经设置了--max-ppsize = 500000和options(表达式= 500000),所以如果你没有设置它们,你可能会得到关于这两件事之一的错误。正如你所看到的,递归可以在这里非常深入,我不知道如何让它一致地工作。谢谢。
f <- function(root=1,lambda=1) {
x <- c(0,1);
prob <- c(1/(lambda+1),lambda/(lambda+1));
repeat {
if(root == 0) {
break;
}
else {
child <- sample(x,2,replace=TRUE,prob);
if(child[1] == 0 && child[2] == 0) {
break;
}
if(child[1] == 1) {
child[1] <- f(root=child[1],lambda);
}
if(child[2] == 1 && child[1] == 0) {
child[2] <- f(root=child[2],lambda);
}
}
if(child[1] == 0 && child[2] == 0) {
break;
}
if(child[1] == 1 || child[2] == 1) {
root <- sample(x,1,replace=TRUE,prob);
}
}
return(root)}
慕丝7291255
泛舟湖上清波郎朗
呼啦一阵风
开心每一天1111
随时随地看视频慕课网APP