Skip to content

Commit d44b60f

Browse files
committed
Don't create a new graphics device on exit in ggsave(). Closes #2363.
1 parent 5f49fb4 commit d44b60f

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
* Data is no longer internally reordered when faceting. This makes it safer to
77
feed data columns into `aes()` or into parameters of geoms or stats. However,
88
doing so remains discouraged (@clauswilke).
9+
10+
* `ggsave()` now exits without creating a new graphics device if previously
11+
none was open (@clauswilke, #2363).
912

1013

1114
# ggplot2 3.0.0

R/save.r

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ ggsave <- function(filename, plot = last_plot(),
5858
dev(filename = filename, width = dim[1], height = dim[2], ...)
5959
on.exit(utils::capture.output({
6060
grDevices::dev.off()
61-
grDevices::dev.set(old_dev)
61+
if (old_dev > 1) grDevices::dev.set(old_dev) # restore old device unless null device
6262
}))
6363
grid.draw(plot)
6464

0 commit comments

Comments
 (0)