I'm trying to import the coordinates of a path in an SVG file created with illustrator into R.
I thought I might read the SVG into R with grImport2, which should in theory be importing SVG files, but I think they might only handle SVG files generated by the Cairo device.
Let's say I want to import the following .svg file:
Here is my attempt at loading an SVG file. If I read the content correctly, it should just contain 1 (complicated) path. The warning is the same one I get when loading my SVG file created by Adobe Illustrator. Be warned that the code below will get stuck for some time!
file <- "https://upload.wikimedia.org/wikipedia/commons/d/db/Brain_Drawing.svg"
download.file(file, tmp <- tempfile(fileext = ".svg"))
# Don't run the following line, it will get your R session stuck!
x <- grImport2::readPicture(tmp)
#> Warning message:
#> In checkValidSVG(doc, warn = warn) :
#> This picture was not generated by Cairo graphics; errors may result
unlink(tmp)
My ideal output would be a data.frame with at least x and y coordinates of (anchor)points and perhaps some metadata that can tell different paths apart. I don't need curves and arcs interpolated or anything like that.
Are there any other packages I'm not aware of that might import this? Is there a way to convert the SVG to one that I can read into R?
