Other Errors
Stack overflow / recursion depth exceeded
Matches: stack overflow|evaluation depth
WHAT THIS ERROR MEANS
Your code has infinite recursion — a function keeps calling itself without a proper stopping condition. R has a limited call stack and this error occurs when it's exceeded.
HOW TO FIX IT
1. Check recursive functions for a proper base case.
2. Look for circular references between functions.
3. Increase the limit with options(expressions = 5000) if recursion is intentional but deep.
CODE EXAMPLES
BAD — THIS CAUSES THE ERROR
f <- function(x) f(x + 1) # no base case f(1)
GOOD — CORRECT APPROACH
f <- function(x) {
if (x > 100) return(x) # base case
f(x + 1)
}
f(1)Still stuck?
Paste your code in RChat and the AI will fix this error in context.
RELATED R ERRORS
Missing value in condition An if statement or while loop received NA instead of TRUE or FALSE. This happens...
Condition has length > 1 An if() statement received a vector with multiple values instead of a single TRU...
Object not found R cannot find a variable or object with the name you used. This usually means yo...
Function not found R doesn't recognize the function you're trying to call. The package containing i...