[R] How to dump plots as bas64 strings?

Gabor Grothendieck ggrothendieck at gmail.com
Thu Mar 5 13:00:35 CET 2009

On Wed, Mar 4, 2009 at 9:17 AM, Patrick Meyer <paterijk at gmail.com> wrote:
> 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")

This isn't much of an improvement and does not even address the main
concern but as no one has answered note that we can pass the filename
as a character string and it will get "rb" automatically and we can
just use "raw" if we like.  Also n can be any size larger than the file
size (see ?readBin) so if the file size is 10000 or less:

readBin("toto.png", "raw", n = 10000, endian = "little")

More information about the R-help mailing list