Is it possible to get R to write a plot in bitmap format (e.g. PNG) to standard output? If so, how?
Specifically I would like to run Rscript myscript.R | other_prog_that_reads_a_png_from_stdin
. I realise it's possible to create a temporary file and use that, but it's inconvenient as there will potentially be many copies of this pipeline running at the same time, necessitating schemes for choosing unique filenames and removing them afterwards.
I have so far tried setting outf <- file("stdout")
and then running either bitmap(file=outf, ...)
or png(filename=outf, ...)
, but both complain ('file' must be a non-empty character string
and invalid 'filename' argument
, respectively), which is in line with the official documentation for these functions.
Since I was able to persuade R's read.table()
function to read from standard input, I'm hoping there's a way. I wasn't able to find anything relevant here on SO by searching for [r] stdout plot
, or any of the variations with stdout
replaced by "standard output"
(with or without double quotes), and/or plot
replaced by png
.
Thanks!