[Rd] Saving R graphics as various file types.

From: Barry Rowlingson <b.rowlingson_at_lancaster.ac.uk>
Date: Wed, 18 Jul 2007 18:29:58 +0100

  I'm using R called via Rpy from Python running from Quantum GIS. Put simply, I'm developing a GUI wrapper round some R plotting functions.

  What I want to do is offer the user a 'Save Plot As...' option.

  The problem is divining what sort of output files R can copy a graphics device into. The 'capabilities()' function gives a few clues, and there should always be postscript and pdf functions, but then if R has the Cairo package then there may be even more options - Tiff, SVG and so on.

  What I'd like is a way of collecting up all the possible graphics output formats so that my Save dialog can list them, and then working out how to do the conversions when the user requests it.

  Perhaps someone has already done this? I think the simplest way may be to hard-code as much as possible initially. For each possible output format have a number of possible ways of producing that output and a test to see if that method is available. Then run the tests and use the best ones found. For example, it's probably better to make a TIFF file using CairoTIFF than using jpeg() and a shell call to ImageMagick's convert routine. But if there's no Cairo, fall back. If there's no jpeg(), or no ImageMagick, then you're stuck, and jpeg output is no longer an option.

  How would this work in practice? Let's think:

> library(graphicsFormats)
> graphicsFormats()

  [1] "png" "pdf" "eps" "tiff" "svg"

> graphicsFormatInfo("png")

  [1] "png ; portable network graphics" "raster"

> graphicsFormatSupport("jpeg")

  Warning message:
  No jpeg support in capabilities() and no Cairo package present   [1] FALSE And then the all important:

> convertTo("png",filePrefix="/foo/bar")

  I'm still pondering the above functions. The basic idea would be to make graphics file format conversions device driver independent. I'm not sure if this is too lofty a goal, since different device drivers will require very different further arguments...

  Anyway, all thoughts welcome.


R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 18 Jul 2007 - 20:18:41 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 19 Jul 2007 - 00:36:52 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.