Last data update: 2014.03.03

R: Cairo callbacks
Cairo.onSaveR Documentation

Cairo callbacks

Description

Cairo.onSave set the onSave callback which allows R code to be run when Cairo finalizes a page (either due to a new page being created or by the device being closed). The callback expects function(device, page) where device will be the device number and page is the currently finished page number (starting at 1).

Usage

Cairo.onSave(device = dev.cur(), onSave)

Arguments

device

device number or Cairo object (as returned by the Cairo function)

onSave

function that will replace the current callback or NULL to remove the current callback

Value

The old callback being replaced or NULL if there was none.

Note

The function onSave will be evaluated in the global environment and no error checking is done, so you must make sure to catch errors, otherwise the behavior is undefined (and may included crashing R or other bad things).

Author(s)

Simon Urbanek

See Also

Cairo

Examples

if (require(png, quietly=TRUE)) {
  dev <- Cairo(800, 600, type='raster')
  Cairo.onSave(dev, function(dev, page)
    .GlobalEnv$png <- writePNG(Cairo.capture(dev))
  )
  plot(1:10, col=2)
  dev.off()
  str(png)
}

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(Cairo)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Cairo/Cairo.onSave.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Cairo.onSave
> ### Title: Cairo callbacks
> ### Aliases: Cairo.onSave
> ### Keywords: device
> 
> ### ** Examples
> 
> if (require(png, quietly=TRUE)) {
+   dev <- Cairo(800, 600, type='raster')
+   Cairo.onSave(dev, function(dev, page)
+     .GlobalEnv$png <- writePNG(Cairo.capture(dev))
+   )
+   plot(1:10, col=2)
+   dev.off()
+   str(png)
+ }
 raw [1:7215] 89 50 4e 47 ...
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>