When debugging a function, I would like to move up to the parent frame and look at some variables there. How do I do this?
Here is a sample:
f <- fun
Just call on.exit(browser())
when browsing f
's body and you'll return back to it after you're done with g()
See output copied from the console below :
> f <- function() {
+ x <-1
+ g(x+1)
+ }
> g <- function(z) {
+ y = z+2
+ return(y)
+ }
> debug("f")
> debug("g")
> f()
debugging in: f()
debug at #1: {
x <- 1
g(x + 1)
}
Browse[2]> on.exit(browser()) # browser() will be run in this environment just before we exit
Browse[2]>
debug at #2: x <- 1
Browse[2]>
debug at #3: g(x + 1)
Browse[2]>
debugging in: g(x + 1)
debug at #1: {
y = z + 2
return(y)
}
Browse[3]>
debug at #2: y = z + 2
Browse[3]>
debug at #3: return(y)
Browse[3]>
exiting from: g(x + 1)
Browse[2]> x # we're back to f so we can investigate x
[1] 1
Browse[2]>
exiting from: f()
[1] 4