|
36 | 36 | #' ggsave("ratings.pdf", ratings, scale=2)
|
37 | 37 | #' }
|
38 | 38 | 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, |
40 | 40 | 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), ...) { |
42 | 42 |
|
43 | 43 | if (!inherits(plot, "ggplot")) stop("plot should be a ggplot2 plot")
|
44 | 44 |
|
@@ -69,9 +69,12 @@ ggsave <- function(filename = default_name(plot), plot = last_plot(),
|
69 | 69 | paste(digest.ggplot(plot), ".pdf", sep="")
|
70 | 70 | }
|
71 | 71 |
|
72 |
| - default_device <- function(filename) { |
| 72 | + default_ext <- function(filename) { |
73 | 73 | pieces <- strsplit(filename, "\\.")[[1]]
|
74 | 74 | ext <- tolower(pieces[length(pieces)])
|
| 75 | + } |
| 76 | + |
| 77 | + default_device <- function(ext) { |
75 | 78 | match.fun(ext)
|
76 | 79 | }
|
77 | 80 |
|
|
0 commit comments