[R] How to dump plots as bas64 strings?

Patrick Meyer paterijk at gmail.com
Wed Mar 4 15:17:57 CET 2009


Hello

My question might sound awkward, but I am looking for a way to somehow
convert a plot in R into a base64 string.

Here's an idea, but it is not at all satisfying.

1. write the plot to the harddisk:
---------------------------
png("toto.png")
plot(c(1,2,3))
dev.off()
---------------------------

2. somehow reload that file from the disk and transform it into a base64
string:
---------------------------
bin<-readBin(file("toto.png","rb"), raw(), n=1000,endian = "little")
...
---------------------------

Using the disk to perform this is not elegant, I don't know what value
to put for n, and I don't like the general idea.

Does anyone have a better suggestion? I have already searched on the
internet and in the mailing list, and I just found something on a
caTools package containing a base64encode & base64decode function.

Thanx for any ideas ...

Patrick




More information about the R-help mailing list