1

I am trying to save a complete dump which allows a good debugging, but I found that some function arguments (e.g. those which are evaluated from global environment), are not saved. I created a simplified example to illustrate this:

covariates <- c("hi", "there", "user")

f <- function (covariates, double_x) 
{
    stop("HI, ERROR!")
}

g <- function (x)
{
    f(covariates, 2*x)
}

options(warn = 1, keep.source = TRUE, show.error.locations = TRUE, error = quote({
    cat("\n====================\nERROR HANDLING ROUTINE\n")
    dump.frames(dumpto = "last.dump", to.file = TRUE, include.GlobalEnv = TRUE)
}))

g(100)

Now, when I am later examining the dump (in a different interactive R session

  • important!), you can see that everything looks fine, but the covariates argument of function is not found:

    load("last.dump.rda") debugger(last.dump) Message: Error in f(covariates, 2 * x) : HI, ERROR! Available environments had calls: 1: .GlobalEnv 2: g(100) 3: #3: f(covariates, 2 * x) 4: #3: stop("HI, ERROR!")

    Enter an environment number, or 0 to exit Selection: Selection: 3 Browsing in the environment with call: #3: f(covariates, 2 * x) Called from: debugger.look(ind) Browse[1]> ls() [1] "double_x" Browse[1]> double_x [1] 200 Browse[1]> covariates Error: object 'covariates' not found

In the end, the covariates variable can be found in the first frame 1: .GlobalEnv; but why is covariates not available in the frame of function f, when it is its argument, thus local to function f? This complicates the debugging a lot... Is there another way to fix it? I am little bothered that this doesn't the same way as the options(error = recover) in the interactive session.

PS: this question is inspired by this answer showing a nice way how to track errors.

Tomas
  • 57,621
  • 49
  • 238
  • 373
  • I cannot replicate this. Both variables return values for me. What version of R are you using? I used R3.6.1. – MrFlick May 17 '20 at 21:05
  • @MrFlick really? That's interesting! I am using R 3.6.1. too! – Tomas May 17 '20 at 22:43
  • But @MrFlick, do you start a new R session for the debugger? If do it in the same, it is obvious that it will work... I am interested in post mortem analysis of the dump file, when the original R session with the error is no longer running. – Tomas May 17 '20 at 22:45
  • 1
    Ah. I restarted R in RStudio but I didn't realize it was auto-reloading the workspace. I now get the same behavior. But I'm more surprised that `double_x` is there than that `covariates` is not from this blurb on the `dump.frames` help page: "Note that not all the information in the original frame will be available, e.g. promises which have not yet been evaluated and the contents of any ... argument." If I had a `force()` to those values before the `stop()`, then they are both there. – MrFlick May 17 '20 at 23:07

0 Answers0