Skip to content

Recursion Limits?

2 messages · Brett Magill, Douglas Bates

#
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) )
   }
[1] 30
[1] 31
...
...
...
[1] 50
[1] 50
[1] 20
[1] 21
...
...
...
[1] 44
[1] 45
Error in ifelse(n < 50, { : evaluation is nested too deeply: infinite recursion?
#
Brett Magill <bmagill at earthlink.net> writes:
Try 

options(expressions = some_large_value)
`expressions': sets a limit on the number of nested expressions
          that will be evaluated.  This is especially important on the
          Macintosh since stack overflow is likely if this is set too
          high.  Valid values are 25...100000 with default 500.