Learn R Programming

berryFunctions (version 1.15.0)

pdfpng: Create pdf and png graph

Description

Create both a pdf and a png file with a graph, with custom size default values. To iteratively create pdfs without closing and reopening the pdf viewer, you might want to use e.g. Sumatra, which comes with Rstudio. It can be found e.g. in C:/Program Files/RStudio/bin/sumatra

Usage

pdfpng(expr, file, pdf = TRUE, png = TRUE, overwrite = FALSE,
  quiet = FALSE, filargs = NULL, width = 7, height = 5, units = "in",
  res = 500, seed = runif(1, -1e+09, 1e+09), envlevel = 1,
  pdfargs = NULL, pngargs = NULL, ...)

Arguments

expr
Expression creating the plot, can be included in curly braces.
file
Character: Filename without pdf/png extension. Unless overwrite=TRUE, files will not be overwritten, but "_1" will be appended instead, see newFilename. If expr creates several plots, use file="fname otherwise the png will only contain the last figure. Note: this overwrites files as the captured by newFilename. You may also have to run dev.off().
pdf
Logical: Create pdf? DEFAULT: TRUE
png
Logical: Create png? DEFAULT: TRUE
overwrite
Logical: Overwrite existing file? Can be a vector for pdf and png separately. DEFAULT: FALSE (_n appended in filename)
quiet
Logical: suppress file creation messages? DEFAULT: FALSE
filargs
List of other arguments passed to newFilename. DEFAULT: NULL
width, height
Graph dimensions. DEFAULT: 7x5 inches
units, res
Graph quality arguments passed only to png. DEFAULT: inches ("in"), 500 ppi
seed
Seed passed to set.seed before each call. DEFAULT: runif(1,-1e9,1e9)
envlevel
Environment level passed to eval.parent. Never needs to be changed, as far as I can tell. DEFAULT: 1
pdfargs
List of arguments only passed to pdf.
pngargs
List of arguments only passed to png.
Further arguments passed to both pdf and png

Value

Nothing

See Also

pdf, png

Examples

Run this code

pdfpng({par(bg=8, las=1); plot(cumsum(rnorm(500)), type="l")}, 
       file="dummyplot", res=100)
pdfpng({par(bg=8, las=1); plot(cumsum(rnorm(500)), type="l")}, 
       file="dummyplot", overwrite=c(TRUE,FALSE))

# Nesting of functions is possible:
a <- list( cumsum(rnorm(2000)), cumsum(rnorm(20)) )
pdfpng(plot(a[[1]]), file="dummyplot", overwrite=TRUE)
bfun <- function(b) pdfpng(plot(b,type="l"), file="dummyplot", overwrite=TRUE)
cfun <- function(c) bfun(c)
bfun(a[[1]])   
sapply(a, function(d) cfun(d))    

       
unlink("dummyplot.pdf") ; unlink("dummyplot.png") ; unlink("dummyplot_1.png")

Run the code above in your browser using DataLab