devEval.RdOpens a new graphics device, evaluate (graphing) code, and closes device.
devEval(type=getOption("device"), expr, initially=NULL, finally=NULL,
envir=parent.frame(), name=NULL, tags=NULL, sep=getDevOption(type, "sep",
default = ","), ..., ext=NULL, filename=NULL, path=getDevOption(type, "path",
default = "figures"), field=getDevOption(type, name = "field"),
onIncomplete=c("remove", "rename", "keep"), force=getDevOption(type, "force",
default = TRUE), which=dev.cur(), .exprAsIs=FALSE, .allowUnknownArgs=FALSE)Specifies the type of graphics device to be used.
The device is created and opened using devNew().
Multiple types may be specified.
The expression of graphing commands to be evaluated.
Optional expression:s to be evaluated
before and after expr. If type specifies multiple
devices, these optional expression:s are only evaluated ones.
The environment where expr should be evaluated.
The fullname name of the image is specified
as the name with optional sep-separated tags appended.
The filename extension of the image file generated, if any.
By default, it is inferred from argument type.
Additional arguments passed to devNew().
The filename of the image saved, if any.
By default, it is composed of arguments name, tags,
sep, and ext. See also below.
The directory where then image should be saved, if any.
An optional character string specifying a specific
field of the named result list to be returned.
A character string specifying what to do with
an image file that was incompletely generated due to an interrupt
or an error.
If TRUE, and the image file already exists, then it is
overwritten, otherwise not.
A vector of devices to be copied. Only applied if
argument expr is missing.
(Internal use only).
Returns a DevEvalFileProduct if the device generated an
image file, otherwise an DevEvalProduct.
If argument field is given, then the field of the
DevEvalProduct is returned instead.
Note that the default return value may be changed in future releases.
If created, the generated image file is saved in the directory
specified by argument path with a filename consisting of
the name followed by optional comma-separated tags
and a filename extension given by argument ext.
By default, the image file is only created if the expr
is evaluated completely. If it is, for instance, interrupted
by the user or due to an error, then any incomplete/blank image
file that was created will be removed. This behavior can be
turned of using argument onIncomplete.
To change default device parameters such as the width or the height,
devOptions().
devNew().
# Plot to PNG using one whatever PNG device driver is available
res <- devEval("{png}", name="MyPlot", tags=c("10", "rnd"), aspectRatio=0.7, {
plot(1:10)
})
print(res$pathname)
#> [1] "../../../../Rtmp5OOCHu/figures/MyPlot,10,rnd.png"
# [1] "figures/MyPlot,10,rnd.png"
str(res$dataURI)
#> chr "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeAAAAFQCAMAAABQwF3SAAAABlBMVEUAAAD///+l2Z/dAAAFgUlEQVR4nO3c0XbaM"| __truncated__
# chr "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeAA..."
## Plot to PDF using grDevices::pdf()
res <- devEval("pdf", name="MyPlot", tags=c("10", "rnd"), aspectRatio=0.7, {
plot(1:10)
})
print(res$pathname)
#> [1] "../../../../Rtmp5OOCHu/figures/MyPlot,10,rnd.pdf"
# [1] "figures/MyPlot,10,rnd.pdf"
## Plot to EPS using R.devices::eps()
res <- devEval("eps", name="MyPlot", tags=c("10", "rnd"), aspectRatio=0.7, {
plot(1:10)
})
print(res$pathname)
#> [1] "../../../../Rtmp5OOCHu/figures/MyPlot,10,rnd.eps"
# [1] "figures/MyPlot,10,rnd.eps"