Skip to content

Commit

Permalink
fix #2166: reset the graphics device after each knit() call
Browse files Browse the repository at this point in the history
dev.off() will move the device to dev.next(), but the next device is not necessarily the one previously opened, so we have to precisely reset to that specific device
  • Loading branch information
yihui committed Oct 4, 2022
1 parent 8fa7d17 commit ff3d767
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: knitr
Type: Package
Title: A General-Purpose Package for Dynamic Report Generation in R
Version: 1.40.1
Version: 1.40.2
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person("Abhraneel", "Sarma", role = "ctb"),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## BUG FIXES

- Plot created outside of `knit()` could sneak into `knit_child()` results (thanks, @niklaswillrich, #2166).

- User-provided background colors for code chunks in `.Rnw` documents may fail (thanks, @nielsrhansen, #2167).

# CHANGES IN knitr VERSION 1.40
Expand Down
1 change: 1 addition & 0 deletions R/block.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ eng_r = function(options) {
# open a device to record plots if not using a global device or no device is
# open, and close this device if we don't want to use a global device
if (!opts_knit$get('global.device') || is.null(dev.list())) {
dv0 = dev.cur(); on.exit(dev.set(dv0), add = TRUE) # reset current device (#2166)
chunk_device(options, keep != 'none', tmp.fig)
dv = dev.cur()
if (!opts_knit$get('global.device')) on.exit(dev.off(dv), add = TRUE)
Expand Down

0 comments on commit ff3d767

Please sign in to comment.