Last chance! 50% off unlimited learning
Sale ends in
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.
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,
...
)
Expression creating the plot, can be included in curly braces.
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().
Logical: Create pdf? DEFAULT: TRUE
Logical: Create png? DEFAULT: TRUE
Logical: Overwrite existing file
? Can be a vector
for pdf and png separately.
DEFAULT: FALSE (_n appended in filename)
Logical: suppress file creation messages and expr execution error tracing? DEFAULT: FALSE
Logical: trace warnings and messages in expr execution? Errors are always traced. Default: !quiet
List of other arguments passed to newFilename
.
DEFAULT: NULL
Graph dimensions. DEFAULT: 7x5 inches
Graph quality arguments passed only to png
.
DEFAULT: inches ("in"), 500 ppi
Seed passed to set.seed
before each call.
DEFAULT: runif(1,-1e9,1e9)
Environment level passed to eval.parent
.
Never needs to be changed, as far as I can tell. DEFAULT: 1
List of arguments only passed to pdf
.
List of arguments only passed to png
.
file paths, invisible
# NOT RUN {
# }
# 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")
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab