Skip to content

Commit 4d2ca99

Browse files
authored
Don't create a new graphics device on exit in ggsave(). Closes #2363. (#2758)
1 parent 442108d commit 4d2ca99

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
@@ -21,6 +21,9 @@
2121
* Data is no longer internally reordered when faceting. This makes it safer to
2222
feed data columns into `aes()` or into parameters of geoms or stats. However,
2323
doing so remains discouraged (@clauswilke).
24+
25+
* `ggsave()` now exits without creating a new graphics device if previously
26+
none was open (@clauswilke, #2363).
2427

2528
* Aesthetic names are now consistently standardised both in `aes()` and in the
2629
`aesthetics` argument of scale functions. Also, the US spelling "color"

R/save.r

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

0 commit comments

Comments
 (0)