В Fri, 12 Apr 2024 12:53:02 +0000 Iago Giné Vázquez <iago.g...@sjd.es> пишет:
> How should I call trace() if f was a function? Let the tracer be quote(debug(g)) and use as.list(body(f)) to determine where it should be injected: f <- function() { message('exists("g") so far is ', exists('g')) g <- function() { flag <- TRUE if (flag) stop('an error') } message('about to run g()') g() } In this example, step number 4 is message("about to run g()"), so injecting a call to debug() before it should work: trace(f, quote(debug(g)), at = 4) f() # exists("g") so far is FALSE # Tracing f() step 4 # <-- at this point debug(g) is run # about to run g() # debugging in: g() # debug at #3: { # flag <- TRUE # if (flag) # stop("an error") # } help(trace) has an extensive example showing how to use it for many similar purposes. -- Best regards, Ivan ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.