Learn R Programming

R.devices (version 2.11.0)

devEval: Opens a new graphics device, evaluate (graphing) code, and closes device

Description

Opens a new graphics device, evaluate (graphing) code, and closes device.

Usage

devEval(type=getOption("device"), expr, initially=NULL, finally=NULL,
  envir=parent.frame(), name=NULL, tags=NULL, sep=getOption("devEval/args/sep", ","),
  ..., ext=NULL, filename=NULL, path=getOption("devEval/args/path", "figures/"),
  field=getOption("devEval/args/field", NULL), onIncomplete=c("remove", "rename",
  "keep"), force=getOption("devEval/args/force", TRUE), which=dev.cur(), .exprAsIs=FALSE)

Arguments

type
Specifies the type of graphics device to be used. The device is created and opened using devNew(). Multiple types may be specified.
expr
The expression of graphing commands to be evaluated.
initially, finally
Optional expression:s to be evaluated before and after expr. If type specifies multiple devices, these optional expression
envir
The environment where expr should be evaluated.
name, tags, sep
The fullname name of the image is specified as the name with optional sep-separated tags appended.
ext
The filename extension of the image file generated, if any. By default, it is inferred from argument type.
...
Additional arguments passed to devNew().
filename
The filename of the image saved, if any. By default, it is composed of arguments name, tags, sep, and ext. See also below.
path
The directory where then image should be saved, if any.
field
An optional character string specifying a specific field of the named result list to be returned.
onIncomplete
A character string specifying what to do with an image file that was incompletely generated due to an interrupt or an error.
force
If TRUE, and the image file already exists, then it is overwritten, otherwise not.
which
A vector of devices to be copied. Only applied if argument expr is missing.
.exprAsIs
(Internal use only).

Value

  • 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.

Generated image file

If created, the generated image file is saved in the directory specfied 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.

See Also

To change default device parameters such as the width or the height, devOptions(). devNew().

Examples

Run this code
res <- devEval("png", name="MyPlot", tags=c("10", "rnd"), aspectRatio=0.7, {
  plot(1:10)
})
print(res$pathname)
# [1] "figures/MyPlot,10,rnd.png"

str(res$dataURI)
# chr "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeAA..."

res <- devEval("pdf", name="MyPlot", tags=c("10", "rnd"), aspectRatio=0.7, {
  plot(1:10)
})
print(res$pathname)
# [1] "figures/MyPlot,10,rnd.pdf"


res <- devEval("eps", name="MyPlot", tags=c("10", "rnd"), aspectRatio=0.7, {
  plot(1:10)
})
print(res$pathname)
# [1] "figures/MyPlot,10,rnd.eps"

Run the code above in your browser using DataLab