Read in a vector file as a
1 2 3 4 5 6 7
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., http://phylopic.org) 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:
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.
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.
Read XML into R. This is done with
grImport::readPicture and creates an object of class
Picture that can be drawn using
eventuall some forest functions.
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
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.xml. If the starting point is an eps file then
this is simply
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.