R: promise is already being evaluated

I understand that you are probably tired of answering the same question, but I still get the error discussed in several other questions :

promise is already being evaluated: recursive default argument argument or earlier problems?

even though I followed the "bulky" add tip "." :

 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) 
  • So what am I still doing wrong?
  • I really need to . in .envir ? What about .exclude and .threshold ?
  • Why am I getting the argument "..." is missing, with no default error?
  • Why am I getting a promise already under evaluation error?

Thanks!

+6
source share
1 answer

When f is called, a stack of 5 levels is built up to show.large.objects , which begins to evaluate the contents of the frames starting at the top.

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

Level 1

 f() 

Everything is good here.

Level 2

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

When you call ls(.envir, all.names) in your frame, you get

 [1] "..." "x" 

of which ... missing, and throws error 3 when you call get on it, and x = system.time(show.large.objects.stack()) is currently 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 evaluated and throws another 4 error.

Level 4

 show.large.objects.stack() 

whose ls does not contain fragmentary things and ends without errors.

Bottom row

show.large.frames() must be evalutad by itself, and not as an argument to any function, or it will cause errors. Why not let yourself print?

I found this very useful.

 > 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" 
+3
source

Source: https://habr.com/ru/post/948108/


All Articles