pdfpng: Create pdf and png graph

View source: R/pdfpng.R

pdfpngR Documentation

Create pdf and png graph

Description

Create both a pdf and a png file with a graph, with custom size default values.
pdfpng tries to open the PDF file (through openPDF) with SumatraPDF viewer, which does not lock files against being edited.
See sumatraInitialize for nice Sumatra default settings.

Usage

pdfpng(
  expr,
  file,
  pdf = TRUE,
  png = TRUE,
  overwrite = FALSE,
  open = TRUE,
  quiet = FALSE,
  tracewarnmes = !quiet,
  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%02d", otherwise the png will only contain the last figure. Note: this overwrites files as the % notation is not 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)

open

Logical: open file(s) after creation using openPDF and openFile? DEFAULT: TRUE

quiet

Logical: suppress file creation messages and expr execution error tracing? DEFAULT: FALSE

tracewarnmes

Logical: trace warnings and messages in expr execution? Errors are always traced. Default: !quiet

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

file paths, invisible

Author(s)

Berry Boessenkool, berry-b@gmx.de, March 2017

See Also

pdf, png

Examples


## Not run:  # excluded from CRAN checks, file opening not wanted
pdfpng(   plot(rnorm(500), type="l")   , file="dummyplot", png=FALSE)

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

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


pdfpng(plot(-10:100, log="y"), "dummyplot",overwr=TRUE,png=FALSE, open=FALSE)
pdfpng({plot(1); plot(dummyobject)}, "dummyplot", overwrite=TRUE, 
       png=FALSE, open=FALSE)


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

## End(Not run)


berryFunctions documentation built on April 12, 2023, 12:36 p.m.