Skip to content

Commit 53edc51

Browse files
authored
Permit function devices to use file argument (#3810)
1 parent d5b339a commit 53edc51

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* `annotation_raster()` adds support for native rasters. For large rasters,
44
native rasters render significantly faster than arrays (@kent37, #3388)
55

6+
* Support graphics devices that use the `file` argument instead of `fileneame`
7+
in `ggsave()` (@bwiernik, #3810)
8+
69
# ggplot2 3.3.0
710

811
* Fix a bug in `geom_raster()` that squeezed the image when it went outside

R/save.r

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,14 @@ plot_dev <- function(device, filename = NULL, dpi = 300) {
149149
force(filename)
150150
force(dpi)
151151

152-
if (is.function(device))
153-
return(device)
152+
if (is.function(device)) {
153+
if ("file" %in% names(formals(device))) {
154+
dev <- function(filename, ...) device(file = filename, ...)
155+
return(dev)
156+
} else {
157+
return(device)
158+
}
159+
}
154160

155161
eps <- function(filename, ...) {
156162
grDevices::postscript(file = filename, ..., onefile = FALSE, horizontal = FALSE,

0 commit comments

Comments
 (0)