browser is like debug but allows exploration in just a specific location of the function.

Example. I create a simple function with a call to browser, call the function, explore variables within the function, and then tell the function to finish running by using the command c (also may use cont). Instead of c, I could have typed n to go into debugging mode for the remainder of the function call, typed where to learn where exactly the function was called (e.g. perhaps the function was not called directly but was within another function that was executing), or Q to quit the execution of the top-level function and return to the command line.
> fcn <- function(x, y){
+   z <- x*y
+   browser()
+   return(z*exp(z))
+ }
> val <- fcn(2, 1.3)
Called from: fcn(2, 1.3)
Browse[1]> x
[1] 2
Browse[1]> y
[1] 1.3
Browse[1]> z
[1] 2.6
Browse[1]> c
> val
[1] 35.00572

Leave a Reply