[R] Recursion Limits?
Douglas Bates
bates at stat.wisc.edu
Tue Apr 15 18:36:49 CEST 2003
Brett Magill <bmagill at earthlink.net> writes:
> 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?
Try
options(expressions = some_large_value)
>From the help page for options
`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.
More information about the R-help
mailing list