How can I convert a plot image to base64 encoding without writing it to disk first (i.e. directly from the R environment)?
Note this shows how to do it from an image file. I am unable to use files since I am running this in an environment with an R interpreter only (i.e. ephemeral storage only)
I have tried using base64Encode()
like so
library(ggplot2)
library(dplyr)
df <- data.frame(
gp = factor(rep(letters[1:3], each = 10)),
y = rnorm(30)
)
ds <- plyr::ddply(df, "gp", plyr::summarise, mean = mean(y), sd = sd(y))
a <- ggplot(df, aes(gp, y)) +
geom_point() +
geom_point(data = ds, aes(y = mean), colour = 'red', size = 3)
library(RCurl)
a %>% base64Encode(.)
But this simply converts the underlying plot data (not the image itself) to base64.
How can I convert an image from the R environment to base64?