Skip to content

Commit

Permalink
Pull out plot hook registration into our function (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley authored Jun 21, 2024
1 parent 8a5de64 commit a6a367d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
10 changes: 1 addition & 9 deletions R/eval.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,7 @@ evaluate_top_level_expression <- function(exprs,
}

local_output_handler(function() handle_output(FALSE))

# Hooks to capture plot creation
hook_list <- list(
persp = handle_output,
before.plot.new = handle_output,
before.grid.newpage = handle_output
)
set_hooks(hook_list)
on.exit(remove_hooks(hook_list), add = TRUE)
local_plot_hooks(handle_output)

# Handlers for warnings, errors and messages
mHandler <- function(cnd) {
Expand Down
11 changes: 11 additions & 0 deletions R/graphics.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
local_plot_hooks <- function(f, frame = parent.frame()) {
hook_list <- list(
persp = f,
before.plot.new = f,
before.grid.newpage = f
)
set_hooks(hook_list)
defer(remove_hooks(hook_list), frame)
invisible()
}

looks_different <- function(old_dl, new_dl) {
if (identical(old_dl, new_dl)) {
return(FALSE)
Expand Down

0 comments on commit a6a367d

Please sign in to comment.