auto_browse: Wrap a function so it will automatically 'browse()' on error

View source: R/adverb-auto-browse.R

auto_browseR Documentation

Wrap a function so it will automatically browse() on error


A function wrapped with auto_browse() will automatically enter an interactive debugger using browser() when ever it encounters an error.





A function to modify, specified in one of the following ways:

  • A named function, e.g. mean.

  • An anonymous function, e.g. ⁠\(x) x + 1⁠ or function(x) x + 1.

  • A formula, e.g. ~ .x + 1. Only recommended if you require backward compatibility with older versions of R.


A function that takes the same arguments as .f, but returns a different value, as described above.


This function is called an adverb because it modifies the effect of a function (a verb). If you'd like to include a function created an adverb in a package, be sure to read faq-adverbs-export.

See Also

Other adverbs: compose(), insistently(), negate(), partial(), possibly(), quietly(), safely(), slowly()


# For interactive usage, auto_browse() is useful because it automatically
# starts a browser() in the right place.
f <- function(x) {
  y <- 20
  if (x > 5) {
  } else {
if (interactive()) {
  map(1:6, auto_browse(f))

purrr documentation built on Aug. 10, 2023, 9:08 a.m.