Skip to content

Instantly share code, notes, and snippets.

@wch
Created February 14, 2019 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wch/61897666937a333a36d244b194fbb7cc to your computer and use it in GitHub Desktop.
Save wch/61897666937a333a36d244b194fbb7cc to your computer and use it in GitHub Desktop.
withRestarts example
f <- function() {
stop("foo")
}
withCallingHandlers(
{
withRestarts({
f()
1
},
my_restart = function() {
message("==== my_restart ====")
# print(sys.calls())
2
}
)
},
error = function(e) {
message("==== withCallingHandler: error ====")
# print(sys.calls())
print(e)
print(computeRestarts())
invokeRestart("my_restart")
}
)
#> ==== withCallingHandler: error ====
#> <simpleError in f(): foo>
#> [[1]]
#> <restart: my_restart >
#>
#> [[2]]
#> <restart: abort >
#> ==== my_restart ====
#> [1] 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment