|
| 1 | +#' Saves the graphic in the active device either as svg or png |
| 2 | +#' |
| 3 | +#' @param filename The Name of the file without suffix (ex. "plot") |
| 4 | +#' @param type The default "vector" saves the graphic as svg, everything else |
| 5 | +#' saves as png (ex. "") |
| 6 | +#' @param path Path where to store the file. If no path is defined, the current |
| 7 | +#' working directory is used. |
| 8 | +#' @param resolution One of "low", "medium" or "high" (only used for png files) |
| 9 | +#' |
| 10 | +#' @importFrom grDevices dev.print dev.size svg |
| 11 | +#' @export |
| 12 | +#' |
| 13 | +saveActiveDevice <- function( |
| 14 | + filename, path = NULL, type = "vector", resolution = "medium" |
| 15 | +){ |
| 16 | + |
| 17 | + if(type == "vector"){ |
| 18 | + dev.print( |
| 19 | + device = svg, |
| 20 | + file = file.path(path, paste0(filename, ".svg")), |
| 21 | + width = dev.size("in")[1], |
| 22 | + height = dev.size("in")[2], |
| 23 | + pointsize = par("ps") |
| 24 | + ) |
| 25 | + |
| 26 | + } else { |
| 27 | + res <- if(resolution == "low"){ |
| 28 | + 200 |
| 29 | + } else if(resolution == "medium"){ |
| 30 | + 500 |
| 31 | + } else if(resolution == "high"){ |
| 32 | + 1000 |
| 33 | + } |
| 34 | + dev.print( |
| 35 | + device = png, |
| 36 | + filename = file.path(path, paste0(filename, ".png")), |
| 37 | + width = dev.size("in")[1], |
| 38 | + height = dev.size("in")[2], |
| 39 | + units = "in", res = res |
| 40 | + ) |
| 41 | + } |
| 42 | +} |
0 commit comments