[R] Recursion Limits?

Brett Magill bmagill at earthlink.net
Tue Apr 15 16:12:04 CEST 2003


See the code below.

First, what are recursion limits in R.  The function is stopping after 25 iterations for me.  Is this general, or localized?  Can recursion limits be changed?

Second, which is generally more efficient, recursion or looping over a function?

R 1.6.1
Windows 98

-----------------------------------------------------------
recurse<-function (n) {
   ifelse(n<50, {print(n); n=n+1; Recall(n)}, print (n) )
   }

>recurse(30)
[1] 30
[1] 31
...
...
...
[1] 50
[1] 50
>

> recurse(20)
[1] 20
[1] 21
...
...
...
[1] 44
[1] 45
Error in ifelse(n < 50, { : evaluation is nested too deeply: infinite recursion?
>



More information about the R-help mailing list