Skip to content

Instantly share code, notes, and snippets.

@ColinFay
Created November 26, 2019 20:52
Show Gist options
  • Save ColinFay/12ad0cc2cf794ec700618aa1a25f2d0e to your computer and use it in GitHub Desktop.
Save ColinFay/12ad0cc2cf794ec700618aa1a25f2d0e to your computer and use it in GitHub Desktop.
browser_n
browser_n <- function(n){
i <- 0
function(...){
i <<- i + 1
if (n >= i){
browser(...)
} else {
invisible(NULL)
}
}
}
browser_once <- browser_n(1)
# Will call browser()
browser_once()
# Won't call browser()
browser_once()
browser_twice <- browser_n(2)
# Will call browser()
browser_twice()
browser_twice()
# Won't call browser()
browser_twice()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment