Description Usage Arguments Details Author(s)
Read in a vector file as a grImport::Picture
object.
1 2 3 4 5 6 7 | vector_read(filename)
vector_read_xml(filename)
vector_read_eps(filename)
vector_read_svg(filename)
|
filename |
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
vectoR:::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
vectoR:::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 grid.picture
.
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.