I have written a recursive function of the form
foo=function(vars,i=2){
**do something with vars**
if(i==length(vars)){
return(**something**)
}else{
foo(vars,i+1)
}
}
length(vars)
is around 1500. When I execute it, I got the error
Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
Error during wrapup: evaluation nested too deeply: infinite recursion / options(expressions=)?
Fair enough, so I increased
options(expressions=10000)
Then it works.
But when I read the help doc of options
regarding expressions=
, i just don't understand what it is saying. Furthermore, it suggests
...If you increase it, you may also want to start R with a larger
protection stack;...
So can someone tell me what's is going on, if I should have increased the expressions
parameters as I have, and if I should modify something else together with it.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…