Browse Interactively in a Function's Frame

DESCRIPTION:
Allows the user to inspect the contents of a function's frame. This is useful when debugging a function.

USAGE:
browser.default(frame=<<see below>>, catch=T, parent=<<see below>>,
         message=<<see below>>, prompt="b> ", readonly=F)

OPTIONAL ARGUMENTS:
frame:
the frame in which the browser will look for information and will evaluate user expressions. By default this is the frame of the function calling browser. Therefore in its usual use, adding the expression to a function allows you to see what the function has done so far.
catch:
logical flag: should errors and interrupts be caught in the browser? If TRUE, then the browser will be restarted after such errors. (However, see the quit signal comment below.) If FALSE, any errors will cause a return to the S-PLUS prompt level.
parent:
the frame to use as the parent of the evaluation frame. By default it is sys.parent(1) if frame is present and sys.parent(2) if it is not.
message:
text to be printed instead of the standard "Browser called from: ..." message.
prompt:
character string to be used as the prompt within the browser call.
readonly:
logical flag: if FALSE and if frame is missing or numeric, assignments will cause changes in the corresponding evaluation frame that persist after the return from browser.default.

VALUE:
the value returned in a return expression typed by the user. If you return by giving a response 0 to the prompt, the value is NULL.

SIDE EFFECTS:
the values of objects are printed if requested. Assignments are also made if readonly is FALSE and frame is missing or numeric.

DETAILS:
When the browser is invoked, you will be prompted for input. The input can be any expression; this will be evaluated in frame. Three kinds of expressions are special. The response ? will get you a list of menu-selectable items (the elements of the frame). A numeric response is taken to be such a selection. Type 0 to get out of the browser. A return expression returns from the browser with this value. The expression substitute(x) is useful to see the actual argument that was given, corresponding to the formal argument x.

Assignment expressions are worth considering, also. If browser is called without an explicit frame argument, as in the example, assignments will take place in the calling function's frame. Thus, browser can be used to try out revisions in real time, without editing the function. A similar use can be made of the case of an explicit frame; assignments will change the frame, as it appears inside browser, so that modifications in the situation as captured in frame (for example, through dump.frames and debugger) can be tried out interactively. Both these versions can be helpful in software design and debugging.

The quit signal (usually the character control-backslash) will exit from the browser, and from the whole expression that generated the call to the browser, returning to the S-PLUS prompt level. (Don't type two control-backslash characters (one if catch=FALSE) since this will terminate your session with S-PLUS.)

This is the default method for the generic function browser.

The inspect function now provides a more general interactive debugging environment, including browsing and tracing, together with most of the functionality of the debugger function.


BUGS:
Typing a comment to the browser will make the next statement behave strangely.

SEE ALSO:
browser , inspect , restart , debugger , trace , dump.calls .

EXAMPLES:
trace(foo, browser) # call browser on entering foo
options(interrupt=browser)
myfun <- function(x,y) {
        # lots of computing
        browser() #now check things just before the moment of truth
        .C("myroutine",x,y,w)
}