Skip to content

Commit dc370c0

Browse files
author
Sebastian Kopf
committed
file extension as a parameter for ggsave to allow specific device matching
parameter to set if the filename extension cannot inform the proper device to use (e.g. in a temp file)
1 parent 485c716 commit dc370c0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

R/save.r

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
#' ggsave("ratings.pdf", ratings, scale=2)
3737
#' }
3838
ggsave <- function(filename = default_name(plot), plot = last_plot(),
39-
device = default_device(filename), path = NULL, scale = 1,
39+
device = default_device(ext), path = NULL, scale = 1,
4040
width = par("din")[1], height = par("din")[2], units = c("in", "cm", "mm"),
41-
dpi = 300, limitsize = TRUE, ...) {
41+
dpi = 300, limitsize = TRUE, ext = default_ext(filename), ...) {
4242

4343
if (!inherits(plot, "ggplot")) stop("plot should be a ggplot2 plot")
4444

@@ -69,9 +69,12 @@ ggsave <- function(filename = default_name(plot), plot = last_plot(),
6969
paste(digest.ggplot(plot), ".pdf", sep="")
7070
}
7171

72-
default_device <- function(filename) {
72+
default_ext <- function(filename) {
7373
pieces <- strsplit(filename, "\\.")[[1]]
7474
ext <- tolower(pieces[length(pieces)])
75+
}
76+
77+
default_device <- function(ext) {
7578
match.fun(ext)
7679
}
7780

0 commit comments

Comments
 (0)