What is the max recursion depth of user function in R?

Viewed 44

I am curious what is the depth of recursion when running a user-defined recursive function. Let's take the following simple function as an example

f <- function(n) {
    if (n <= 2) {
        return(n)
    }
    mean(c(f(n - 1), f(n - 2)))
}

As seen above, the function is written in a recursive manner.

When I ran f(2000), I was given

> f(2000)
Error: evaluation nested too deeply: infinite recursion / options(expressions=)?

Is there any limitation of recursion numbers in R? If there is, where can I find it or how should I know the limitation?

0 Answers
Related