move up a frame, debug R environment

后端 未结 3 2109
终归单人心
终归单人心 2021-01-31 10:18

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         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-31 11:05

    You can use recover (it is often used to debug code after an actual error, via options(error=utils::recover), but it can be called directly).

    > f()
    debugging in: g(x + 1)
    debug at #1: {
        y = z + 2
        return(y)
    }
    Browse[2]> ls()
    [1] "z"
    Browse[2]> recover()
    
    Enter a frame number, or 0 to exit   
    
    1: f()
    2: #3: g(x + 1)
    
    Selection: 1
    Called from: top level 
    Browse[3]> ls()
    [1] "x"
    Browse[3]> x
    [1] 1
    Browse[3]> 
    

提交回复
热议问题