C stack usage 7970960 is too close to the limit

Viewed 1703

I tried to compute a simple exponential function in RStudio as,

> exp(1)

And I received following error message:

Error: C stack usage 7970960 is too close to the limit

Now I can't run any exponential computing in RStudio anymore but last night it was all good! I tried to do it in regular R and it works. So weird. I tried to expand the limit in terminal (I am using Mac) but that seems not to stay permanent..

What happens to computation? Does anyone know how to remove this error?

1 Answers

You almost certainly have a bogus function called exp in your search path somewhere, which calls itself. It may be in your workspace (global environment), or (less likely but possible) in a package you have loaded. (It's also possible that the infinite recursion is defined in a more complicated way, i.e. rather than exp() calling itself, it calls something that calls it back ...)

The normal, expected result of find("exp") is

[1] "package:base"

Suppose you have defined a recursive exp function in your workspace:

exp <- function(x) exp(x)

Then exp(1) will give

Error: C stack usage 7969716 is too close to the limit

and find("exp") will give

[1] ".GlobalEnv" "package:base"

i.e. there is an exp in the global environment that R will see before it sees the built-in function in the base package.

If you do have something like this going on, starting a new R session will help (unless the object is in a saved workspace that gets restored when the session starts), or rm("exp").

Related