Reputation: 529
Is there a generic way to supply a function which expects a text file as input with a string instead?
I want to convert 56000+ svg 'files' into a raster/grid format (bitmap, png or similar)
But the svg files are not stored as files, but rather as strings in a data frame
I thought I could use textConnection but I'm not having any luck:
> pseudo_file <- textConnection(data[1,"svg"])
> bitmap <- rsvg(pseudo_file)
Error: is.raw(svg) is not TRUE
Upvotes: 1
Views: 202
Reputation: 5958
The below works for me. Make sure that the strings are recognized as correct URL's for R: the \
should be replaced by \\
or /
.
library(rsvg)
myfiles <- c("example.svg" , "example.svg")
for(i in myfiles) {
test <- rsvg(i)
}
test
If the SVG is a string, you can use charToRaw
to convert SVG strings into raw data.
Upvotes: 1