Donald Paul Winston
2010-Aug-19 01:49 UTC
[R] Does R always insist on sending plot output to a file?
I need to write the output of a R plot to a Java OutputStream. It looks like R insists on sending it's output to a file. Is there anyway to get bytes directly from the output of a plot so I can write it with Java? Writing it to a file is too slow. Is there a parameter in the graphics device function png(..) that directs output to a variable in memory? x <- plot(.) would make sense. -- View this message in context: http://r.789695.n4.nabble.com/Does-R-always-insist-on-sending-plot-output-to-a-file-tp2330557p2330557.html Sent from the R help mailing list archive at Nabble.com.
Henrique Dallazuanna
2010-Aug-19 01:53 UTC
[R] Does R always insist on sending plot output to a file?
Take a look on help page for ?recordPlot On Wed, Aug 18, 2010 at 10:49 PM, Donald Paul Winston < satchwinston@yahoo.com> wrote:> > I need to write the output of a R plot to a Java OutputStream. It looks > like > R insists on sending it's output to a file. Is there anyway to get bytes > directly from the output of a plot so I can write it with Java? Writing it > to a file is too slow. > > Is there a parameter in the graphics device function png(..) that directs > output to a variable in memory? > > x <- plot(.) would make sense. > -- > View this message in context: > http://r.789695.n4.nabble.com/Does-R-always-insist-on-sending-plot-output-to-a-file-tp2330557p2330557.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Matt Shotwell
2010-Aug-19 03:21 UTC
[R] Does R always insist on sending plot output to a file?
Donald, At least for the PDF device (I know you asked about png, but I believe they are similar), the answer no. Ultimately, this device calls the standard C function fopen, and writes its data to the resulting file stream. If you're using GNU Linux, you might trick R into writing to a fifo (a named pipe, see 'man fifo'), or some other in-memory device, and read from it with another program. My initial experiments with this, however, were not successful. A better solution here, would be to have the various graphics devices write to an R connection, as do most other R functions that input and output data. In this way, we could write graphics data to a RAW connection (rawConnection()), which is essentially a memory buffer. There are two obvious barriers to this: 1. C level I/O routines (e.g. fprintf) are heavily integrated into the graphics device code. Hence, accommodating R connections would require significant changes. 2. The graphics devices are mostly implemented in C, and there is (at present) no interface to R connections at the C level. -Matt On Wed, 2010-08-18 at 21:49 -0400, Donald Paul Winston wrote:> I need to write the output of a R plot to a Java OutputStream. It looks like > R insists on sending it's output to a file. Is there anyway to get bytes > directly from the output of a plot so I can write it with Java? Writing it > to a file is too slow. > > Is there a parameter in the graphics device function png(..) that directs > output to a variable in memory? > > x <- plot(.) would make sense.-- Matthew S. Shotwell Graduate Student Division of Biostatistics and Epidemiology Medical University of South Carolina