Created
November 26, 2019 20:52
-
-
Save ColinFay/12ad0cc2cf794ec700618aa1a25f2d0e to your computer and use it in GitHub Desktop.
browser_n
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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