Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

Cairo.onSave

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

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)
}

Cairo

R Graphics Device using Cairo Graphics Library for Creating High-Quality Bitmap (PNG, JPEG, TIFF), Vector (PDF, SVG, PostScript) and Display (X11 and Win32) Output

v1.5-12.2
GPL-2
Authors
Simon Urbanek <Simon.Urbanek@r-project.org>, Jeffrey Horner <jeff.horner@vanderbilt.edu>
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.