Skip to content

Commit

Permalink
Refactor data structure used for looping (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley authored Jul 1, 2024
1 parent d8f00ea commit de8321b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions R/eval.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ evaluate <- function(input,
watcher$push(err)
return(watcher$get())
}
# "Transpose" parsed so we get a list that's easier to iterate over
tles <- Map(
function(src, exprs) list(src = src, exprs = exprs),
parsed$src, parsed$expr
)

if (is.list(envir)) {
envir <- list2env(envir, parent = enclos %||% parent.frame())
Expand All @@ -104,18 +109,18 @@ evaluate <- function(input,
# The user's condition handlers have priority over ours
handlers <- c(user_handlers, evaluate_handlers)

for (i in seq_len(nrow(parsed))) {
watcher$push_source(parsed$src[[i]], parsed$expr[[i]])
for (tle in tles) {
watcher$push_source(tle$src, tle$exprs)
if (debug || log_echo) {
cat_line(parsed$src[[i]], file = stderr())
cat_line(tle$src, file = stderr())
}

continue <- withRestarts(
with_handlers(
{
for (expr in parsed$expr[[i]]) {
ev <- withVisible(eval(expr, envir))
watcher$capture_plot_and_output()
for (expr in tle$exprs) {
ev <- withVisible(eval(expr, envir))
watcher$capture_plot_and_output()
watcher$print_value(ev$value, ev$visible)
}
TRUE
Expand Down

0 comments on commit de8321b

Please sign in to comment.