R Yoda R Yoda - 8 months ago 41
R Question

R: How make dump.frames() include all variables for later post-mortem debugging with debugger()

I have the following code which provokes an error and writes a dump of all frames using

as proposed e. g. by Hadley Wickham:

a <- -1
b <- "Hello world!"
bad.function <- function(value)
log(value) # the log function may cause an error or warning depending on the value

tryCatch( {
a.local.value <- 42
error = function(e)
dump.frames(to.file = TRUE)

When I restart the R session and load the dump to debug the problem via

load(file = "last.dump.rda")

I cannot find my variables (a, b, a.local.value) nor my function "bad.function" anywhere in the frames.

This makes the dump nearly worthless to me.

What do I have to do to see all my variables and functions for a decent post-mortem analysis?

The output of

> load(file = "last.dump.rda")
> debugger(last.dump)
Message: non-numeric argument to mathematical functionAvailable environments had calls:
1: tryCatch({
a.local.value <- 42
2: tryCatchList(expr, classes, parentenv, handlers)
3: tryCatchOne(expr, names, parentenv, handlers[[1]])
4: value[[3]](cond)

Enter an environment number, or 0 to exit

PS: I am using R3.3.2 with RStudio for debugging.


Note that it is often more productive to work with the R Core team rather than just telling that R has a bug. It clearly has no bug, here, as it behaves exactly as documented.

Also there is no problem if you work interactively, as you have full access to your workspace (which may be LARGE) there, so the problem applies only to batch jobs (as you've mentioned).

What we rather have here is a missing feature and feature requests (and bug reports!) should happen on the R bug site (aka _'R bugzilla'), https://bugs.r-project.org/ ... typically however after having read the corresponding page on the R website: https://www.r-project.org/bugs.html.

Note that R bugzilla is searchable, and in the present case, you'd pretty quickly find that Andreas Kersting made a nice proposal (namely as a wish, rather than claiming a bug), https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17116 and consequently I had added the missing feature to R, on Aug.16, already. Yes, of course, the development version of R, aka R-devel. See also today's thread on the R-devel mailing list, https://stat.ethz.ch/pipermail/r-devel/2016-November/073378.html