Skip to content

Commit

Permalink
Also handle creation of graphics device
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Jun 19, 2024
1 parent a7bd643 commit 07a4f7a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 1 addition & 10 deletions R/eval.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,12 @@ evaluate <- function(input,
}
local_inject_funs(envir)

if (new_device) {
# Ensure we have a graphics device available for recording, but choose
# one that's available on all platforms and doesn't write to disk
pdf(file = NULL)
dev.control(displaylist = "enable")
dev <- dev.cur()
on.exit(dev.off(dev))
}

# if this env var is set to true, always bypass messages
if (tolower(Sys.getenv('R_EVALUATE_BYPASS_MESSAGES')) == 'true')
keep_message = keep_warning = NA

# Capture output
watcher <- watchout(output_handler, debug = debug)
watcher <- watchout(output_handler, new_device = new_device, debug = debug)

out <- vector("list", nrow(parsed))
for (i in seq_along(out)) {
Expand Down
10 changes: 10 additions & 0 deletions R/watcher.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
watchout <- function(handler = new_output_handler(),
new_device = TRUE,
debug = FALSE,
frame = parent.frame()) {
last_plot <- NULL

if (new_device) {
# Ensure we have a graphics device available for recording, but choose
# one that's available on all platforms and doesn't write to disk
pdf(file = NULL)
dev.control(displaylist = "enable")
dev <- dev.cur()
defer(dev.off(dev), frame)
}

# record current devices
devs <- dev.list()
devn <- length(devs)
Expand Down

0 comments on commit 07a4f7a

Please sign in to comment.