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

devEval {R.devices} | R Documentation

## 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=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)

### 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`:s are only evaluated ones.
`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, .allowUnknownArgs` | (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`.

### Author(s)

Henrik Bengtsson

### See Also

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

### Examples

    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"

[Package R.devices version 2.15.1 Index]