Saving workspace (in a specific frame) for deferring deferment in R

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.

+4
source share
1 answer
 save(list=ls(), file="mylocals.Rda") 

The obstacle that I had to overcome in order to understand that this was the way forward was called this argument in save . Why did the authors use the name of the argument, "list", when it was a symbol vector (not a list)? The same whine applies to the argument names of the rm function.

+6
source

Source: https://habr.com/ru/post/1495010/


All Articles