Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: promise already under evaluation

I understand that you are probably sick and tired of answering the same question again, but I am still getting the error discussed in several other questions:

promise already under evaluation: recursive default argument reference or earlier problems?

even though I did follow the "cumbersome" advice of prepending ".":

show.large.objects.threshold <- 100000
show.large.objects.exclude <- c("closure")
show.large.objects <- function (.envir = sys.frame(),
                                threshold = show.large.objects.threshold,
                                exclude = show.large.objects.exclude) {
  for (n in print(ls(.envir, all.names = TRUE))) tryCatch({
    o <- get(n,envir = .envir)
    s <- object.size(o)
    if (s > threshold && !(typeof(o) %in% exclude)) {
      cat(n,": ")
      print(s,units="auto")
    }
  }, error = function(e) { cat("n=",n,"\n"); print(e) })
}
show.large.objects.stack <- function (.threshold = show.large.objects.threshold,
                                      skip.levels = 1,# do not examine the last level - this function
                                      .exclude = show.large.objects.exclude) {
  for (level in 1:(sys.nframe()-skip.levels)) {
    cat("*** show.large.objects.stack(",level,") ")
    print(sys.call(level))
    show.large.objects(.envir = sys.frame(level), threshold = .threshold, exclude = .exclude)
  }
}

but I still get errors:

> f <- function () { c <- 1:1e7; d <- 1:1e6; print(system.time(show.large.objects.stack())) }
> f()
*** show.large.objects.stack( 1 ) f()
[1] "c" "d"
c : 38.1 Mb
d : 3.8 Mb
*** show.large.objects.stack( 2 ) print(system.time(show.large.objects.stack()))
[1] "..." "x"  
n= ... 
<simpleError in get(n, envir = .envir): argument "..." is missing, with no default>
n= x 
<simpleError in get(n, envir = .envir): promise already under evaluation: recursive default argument reference or earlier problems?>
*** show.large.objects.stack( 3 ) system.time(show.large.objects.stack())
[1] "expr"    "gcFirst" "ppt"     "time"   
n= expr 
<simpleError in get(n, envir = .envir): promise already under evaluation: recursive default argument reference or earlier problems?>
          user         system        elapsed 
    0 (0.00ms)     0 (0.00ms) 0.002 (2.00ms) 
  1. So, what am I still doing wrong?
  2. Do I really need the . in .envir? What about .exclude and .threshold?
  3. Why do I get the argument "..." is missing, with no default error?
  4. Why do I get the promise already under evaluation error?

Thanks!

like image 604
sds Avatar asked Jun 26 '13 02:06

sds


1 Answers

When f is called a stack of 5 levels is built down to show.large.objects, which starts to evaluate the contents of the frames starting from the top.

f
  -> print
     -> system.time
        -> show.large.objects.stack
           -> show.large.objects

Level 1

f()

Everything ok here.

Level 2

print(system.time(show.large.objects.stack()))

When you call ls(.envir, all.names) on its frame you get

[1] "..." "x"  

of which ... is missing and throws error 3 when you call get on it, and x = system.time(show.large.objects.stack()) is currently being evaluated and throws error 4.

Level 3

system.time(show.large.objects.stack())

whose ls gives you

[1] "expr"    "gcFirst" "ppt"     "time"   

of which expr = show.large.objects.stack() is still currently being evaluated and throws another of error 4.

Level 4

show.large.objects.stack()

whose ls contain no sketchy things and completes without errors.

Bottom line

show.large.frames() must be evalutad on its own, not as an argument to any function, or it will throw errors. Why not letting it do the printing itself?

I found this very helpful

> debug(show.large.objects)
> f()
Browse[2]> lapply(sys.frames(), ls)
[[1]]
[1] "c" "d"

[[2]]
[1] "x"

[[3]]
[1] "expr"    "gcFirst" "ppt"     "time"   

[[4]]
[1] "level"       "skip.levels"

[[5]]
[1] "exclude"   "threshold"
like image 60
Backlin Avatar answered Nov 11 '22 04:11

Backlin