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.