browser
Browse Interactively in a Function's Frame

Description

Interrupts the execution of a function, and allows the user to inspect the contents of the function frame.

Usage

browser(text = "", condition = NULL, expr = TRUE, skipCalls = 0L) 

Arguments

text an object that can be retrieved once the browser is invoked.
condition an object that can be retrieved once the browser is invoked.
expr a logical value. If TRUE (the default), invoke the debugger.
skipCalls a integer. Specifies how many functions to skip when reporting the calling context.

Details

Normally browser is called within a function. It prints a browser prompt, and then puts the engine into a special state that allows you to execute the function interactively and explore the contents of the function frame.
At the browser prompt, the following commands are accepted:
n Executes the next expression in the code. It also enters "step-through" mode, where just pressing Return is the same as entering 'n'.
c or cont In normal mode, this quits the browser and continues execution. In "step-through" mode, typing c or cont continues to the end of the current loop or function. In normal mode, just pressing Return is the same as entering c.
where Prints the call stack.
Q Quits both the browser and the current expression, and returns to the top-level prompt.
At the browser prompt, you can also enter any expression. For example, you can enter ls() to list the objects in the current frame. Entering the name of an object prints it. Errors in code executed at the browser prompt normally return control to the browser prompt.
Assignments and replacements have a lasting effect in that frame after the browser exits. This design allows interactive change to the behavior of a function. Be sure that is what you mean if you do assignments under these conditions. If necessary, objects can be assigned to the workspace from the browser prompt by using <<- if the name is not already in scope.
References
Chambers, John M. 1998. Programming with Data. New York, NY: Springer.
Becker, R. A., Chambers, J. M., and Wilks, A. R. 1988. The New S Language. Pacific Grove, CA: Wadsworth & Brooks/Cole Advanced Books and Software.
See Also
browserText, browserCondition, recover, restart, debugger, trace.
Examples
myfun <- function() {
  for(x in 1:10) {
    # invoke browser in middle of loop
    if (x==5) browser()
    print(x)
  }
}
myfun()
Package base version 6.1.1-7
Package Index