6

我了解您可能已经厌倦了再次回答同一个问题,但我仍然收到其他几个 问题中讨论的错误:

承诺已经在评估中:递归默认参数引用或早期问题?

即使我确实遵循了前置的“繁琐”建议"."

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)
  }
}

但我仍然收到错误:

> 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. 那么,我仍然做错了什么?
  2. 真的需要.in.envir吗?.exclude和怎么样.threshold
  3. 为什么我会收到argument "..." is missing, with no default错误消息?
  4. 为什么我会收到promise already under evaluation错误消息?

谢谢!

4

1 回答 1

3

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"
于 2013-07-03T15:54:22.507 回答