When debugging some R-code, I would like to save the work area (i.e. all existing objects) in a specific frame so that I can use these objects outside the debug browser . Following the example given in this answer :
x <- 1:5 y <- x + rnorm(length(x),0,1) f <- function(x,y) { y <- c(y,1) lm(y~x) }
Setting options(error = recover) and running f(x,y) allows us to choose which frame to enter. Here I will take 2 and spend my workspace using ls() as follows:
Browse[1]> ls() [1] "cl" "contrasts" "data" "formula" "m" "method" "mf" "model" "na.action" "offset" "qr" [12] "ret.x" "ret.y" "singular.ok" "subset" "weights" "x" "y"
I would like to save all these objects so that I can use them later. Using save.image() in the browser or inserting it into the corresponding function, it is initially called from the environment f(x,y) . I can use dump.frames() and call debugger() on the resulting dump.frames object, but I still have to work interactively from within the debug browser. All I really need is a .RData file containing the 18 objects listed above.
The purpose of all this is to reproduce certain errors in the R Markdown document. If anyone has an idea for this particular application, this will be appreciated.
source share