2

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?

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
Phoebe
  • 53
  • 5
  • I can run " exp(1) " in regular R (not R studio) but it doesn't work in R studio. – Phoebe Nov 04 '20 at 21:31
  • 1
    what are the results of `find("exp")` in RStudio? – Ben Bolker Nov 04 '20 at 22:41
  • RStudio is just an IDE, i.e. a fancy script editor. There's absolutely no way that you would get different behaviour in the R console vs. through RStudio. – Phil Nov 04 '20 at 22:46
  • 1
    Yes, but the OP could be working with different environments, one of which contains the bogus recursive function and the other of which does not. – Ben Bolker Nov 04 '20 at 22:47

1 Answers1

1

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").

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453