Skip to content

Commit

Permalink
More refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Jun 19, 2024
1 parent 1a0d3af commit 6c60bae
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions R/eval.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,14 @@ evaluate_top_level_expression <- function(exprs,
}
}

if (use_try) {
handle <- function(code) {
tryCatch(code, error = function(err) {
list(value = NULL, visible = FALSE)
})
handle_error <- function(code) {
if (use_try) {
tryCatch(code, error = function(err) NULL)
} else {
code
}
} else {
handle <- force
}

if (include_timing) {
timing_fn <- function(x) system.time(x)[1:3]
} else {
Expand All @@ -231,7 +230,7 @@ evaluate_top_level_expression <- function(exprs,
for (expr in exprs) {
srcindex <- length(output)
time <- timing_fn(
ev <- handle(
ev <- handle_error(
with_handlers(
withVisible(eval(expr, envir)),
handlers
Expand All @@ -242,12 +241,12 @@ evaluate_top_level_expression <- function(exprs,
if (!is.null(time))
attr(output[[srcindex]]$src, 'timing') <- time

if (show_value(output_handler, ev$visible)) {
if (!is.null(ev) && show_value(output_handler, ev$visible)) {
# Ideally we'd evaluate the print() generic in envir in order to find
# any methods registered in that environment. That, however, is
# challenging and only makes a few tests a little simpler so we don't
# bother.
handle(
handle_error(
with_handlers(
handle_value(output_handler, ev$value, ev$visible),
handlers
Expand Down

0 comments on commit 6c60bae

Please sign in to comment.