|
12 | 12 | #' @param filename file name/filename of plot
|
13 | 13 | #' @param plot plot to save, defaults to last plot displayed
|
14 | 14 | #' @param device device to use, automatically extract from file name extension
|
15 |
| -#' (or from paramter \code{ext} if specified) |
16 | 15 | #' @param path path to save plot to (if you just want to set path and not
|
17 | 16 | #' filename)
|
18 | 17 | #' @param scale scaling factor
|
|
23 | 22 | #' @param limitsize when \code{TRUE} (the default), \code{ggsave} will not
|
24 | 23 | #' save images larger than 50x50 inches, to prevent the common error of
|
25 | 24 | #' specifying dimensions in pixels.
|
26 |
| -#' @param ext file extension to use for choosing the correct device (pdf, jpg, png, etc.), |
27 |
| -#' uses extension of the filename by default, specify if filename does not have |
28 |
| -#' an instructive extension (or none at all, e.g. in a temporary file) |
29 | 25 | #' @param ... other arguments passed to graphics device
|
30 | 26 | #' @export
|
31 | 27 | #' @examples
|
|
40 | 36 | #' ggsave("ratings.pdf", ratings, scale=2)
|
41 | 37 | #' }
|
42 | 38 | ggsave <- function(filename = default_name(plot), plot = last_plot(),
|
43 |
| - device = default_device(ext), path = NULL, scale = 1, |
| 39 | + device = default_device(filename), path = NULL, scale = 1, |
44 | 40 | width = par("din")[1], height = par("din")[2], units = c("in", "cm", "mm"),
|
45 |
| - dpi = 300, limitsize = TRUE, ext = default_ext(filename), ...) { |
| 41 | + dpi = 300, limitsize = TRUE, ...) { |
46 | 42 |
|
47 | 43 | if (!inherits(plot, "ggplot")) stop("plot should be a ggplot2 plot")
|
48 | 44 |
|
@@ -73,14 +69,10 @@ ggsave <- function(filename = default_name(plot), plot = last_plot(),
|
73 | 69 | paste(digest.ggplot(plot), ".pdf", sep="")
|
74 | 70 | }
|
75 | 71 |
|
76 |
| - default_ext <- function(filename) { |
| 72 | + default_device <- function(filename) { |
77 | 73 | pieces <- strsplit(filename, "\\.")[[1]]
|
78 | 74 | ext <- tolower(pieces[length(pieces)])
|
79 |
| - } |
80 |
| - |
81 |
| - default_device <- function(ext) { |
82 |
| - tryCatch(match.fun(ext), error = function(e) |
83 |
| - stop(sprintf("Cannot find a graphics device that matches file extension '%s'.", ext))) |
| 75 | + match.fun(ext) |
84 | 76 | }
|
85 | 77 |
|
86 | 78 | units <- match.arg(units)
|
|
0 commit comments