Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exit current browser (return one level)

Tags:

r

Sometimes you throw multiple browsers into a function to debug. I know you can exit the whole shebang with Q but what if you want to exit the second browser (see below's code) and return to the first level of browser? I've heard type c but that doesn't exit the second level browser.

FUN <- function() {
browser()                      #first one
    lapply(1:10, function(x) {
browser()                      #second one
        return(x)
    })
}

FUN()
like image 607
Tyler Rinker Avatar asked Dec 01 '12 19:12

Tyler Rinker


1 Answers

I agree with Josh and would like to suggest these two alternatives to your current code:

1) debugonce: If we call foo your inner function, then debugonce(foo) will launch the debugger only the first time that foo is called, when x==1.

FUN <- function() {
  browser()
  foo <- function(x)return(x)
  debugonce(foo)
  lapply(1:10, foo)
}

2) debug and undebug. After you run debug(foo), the debugger will be launched every time foo is called, and until you run undebug(foo):

FUN <- function() {
  browser()
  foo <- function(x)return(x)
  debug(foo)
  lapply(1:10, foo)
}

When you want to stop debugging foo, type undebug(foo) before hitting c and it will take you back to the first level browser.

like image 84
flodel Avatar answered Sep 23 '22 02:09

flodel