vector_read: Load Vector Graphics as a Picture Object

Description Usage Arguments Details Author(s)


Read in a vector file as a grImport::Picture object.








filename of a vector object in svg, eps, or eps.xml format.


This is a bit of a Rube Goldberg machine because of a disconnect between how most vector images are likely to be found (SVG, e.g., and the formats that R is capable of reading. There are a number of steps here that require external programs, and cause potential platform non-indepenence. The process is:

  1. Convert SVG to EPS. This can be done with Inkscape automatically, or with other programs manually. The fucntion forest:::inkscape_svg_to_eps function does this step, but requires Inkscape to be installed.

  2. Convert EPS to XML. grImport::readPicture has an internal XML format that it uses, called RGML. To convert to this format, it uses ghostscript to process the EPS file and then does some post-processing. The function forest:::ghostscript_eps_to_xml does this step, but requires ghostscript to be installed.

  3. Read XML into R. This is done with grImport::readPicture and creates an object of class Picture that can be drawn using grid.picture and eventuall some forest functions.

The function vector_read is a high level wrapper to this process that attempts to do as little work as possible. This means that if an XML file that corresponds to an EPS/SVG file exists, that file will be read rather than going back and recreating the XML file. This means that not all of the conversion software needs to installed if the processed files exist.

Alternatively, vector_read_svg, vector_read_eps and vector_read_xml will do all the necessary processing and read the resulting object in as a Picture. They will always reprocess files though.

The above functions use a set of conventions for filenames: picture.svg becomes picture.eps becomes picture.xml. If the starting point is an eps file then this is simply picture.eps becomes picture.xml.

Reading in the XML files can be quite slow. I may add an additional step here that serialises the object as RDS and read from the preferentially. In this case the processed picture.xml becomes picture.rds.


Rich FitzJohn

richfitz/forest documentation built on May 27, 2019, 8:17 a.m.