-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is the culmination of all the evaluate() refactoring I've been working on — we can now define the handlers once (instead of once per top-level expression) and evaluate_tle() becomes sufficiently simple that we can inline it, making the double-loop strategy more clear. Includes a test and news bullet tracking the change in behaviour in `evaluate("stop(1);2")`, and corrects the source handler now that I better understand the data structures involved.
- Loading branch information
Showing
8 changed files
with
147 additions
and
141 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
condition_handlers <- function(watcher, on_error, on_warning, on_message) { | ||
list( | ||
message = function(cnd) { | ||
watcher$capture_plot_and_output() | ||
|
||
if (on_message$capture) { | ||
watcher$push(cnd) | ||
} | ||
if (on_message$silence) { | ||
invokeRestart("muffleMessage") | ||
} | ||
}, | ||
warning = function(cnd) { | ||
# do not handle warnings that shortly become errors or have been silenced | ||
if (getOption("warn") >= 2 || getOption("warn") < 0) { | ||
return() | ||
} | ||
|
||
watcher$capture_plot_and_output() | ||
if (on_warning$capture) { | ||
cnd <- sanitize_call(cnd) | ||
watcher$push(cnd) | ||
} | ||
if (on_warning$silence) { | ||
invokeRestart("muffleWarning") | ||
} | ||
}, | ||
error = function(cnd) { | ||
watcher$capture_plot_and_output() | ||
|
||
cnd <- sanitize_call(cnd) | ||
watcher$push(cnd) | ||
|
||
switch(on_error, | ||
continue = invokeRestart("eval_continue"), | ||
stop = invokeRestart("eval_stop"), | ||
error = invokeRestart("eval_error", cnd) | ||
) | ||
} | ||
) | ||
} | ||
|
||
|
||
with_handlers <- function(code, handlers) { | ||
if (!is.list(handlers)) { | ||
stop("`handlers` must be a list", call. = FALSE) | ||
} | ||
|
||
call <- as.call(c(quote(withCallingHandlers), quote(code), handlers)) | ||
eval(call) | ||
} | ||
|
||
sanitize_call <- function(cnd) { | ||
if (identical(cnd$call, quote(eval(expr, envir)))) { | ||
cnd$call <- NULL | ||
} | ||
cnd | ||
} |
This file contains 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
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.