Re: [R] Image from bytes streams

From: Henrik Bengtsson <>
Date: Tue 16 Aug 2005 - 18:00:14 EST

The R graphics is not sent to the standard output of the R process, which you assume when you try to "capture" it via your Java 'input' stream. Simple illustration:

C:\>echo plot(1) | R --quiet --no-save
 > plot(1)

So where did the graphics go then? If you "batch" run R commands like this, all graphical output is written to (one) default postscript file ""; that's the file you want to read. I bet you have a two page file for your pie and scatter plot. If you do not want postscript, but other formats, you have to generate you image files explicitly, e.g.

png("image.png", width=640, height=480)

Make sure you understand how R works before you try to call it from Java; there is nothing magic going on if you understand it.


Henrik Bengtsson

Márcio de Medeiros Ribeiro wrote:
> Hello!
> I'm trying to get an array of bytes from graphic images generated by
> R. Here, you can see my Java code:
> --------------------------------------------------------------------------------------------------------------------------
> Process p = Runtime.getRuntime().exec("C:/Arquivos de
> programas/R/rw1090/bin/Rterm.exe --no-save");
> DataOutputStream output = new DataOutputStream(new
> BufferedOutputStream(p.getOutputStream()));
> DataInputStream input = new DataInputStream(new
> BufferedInputStream(p.getInputStream()));
> // output.writeBytes("pie(c(50,30,20))"); //Pie graphic
> output.writeBytes("plot(1,1)"); // Plot graphic
> output.flush();
> input.readFully(new byte[200]); // Here I read the "image" bytes.
> --------------------------------------------------------------------------------------------------------------------------
> That's the problem: when I use Pie graphic, I got some bytes. However,
> when I use the Plot graphic, I got the same bytes! So, I suppose that
> my program does not read the bytes from the generated graphic from R.
> Is it possible to get the bytes from the generated graphic? How can I
> get these bytes?
> Sorry about my english. I'm brazilian! :) mailing list PLEASE do read the posting guide! Received on Tue Aug 16 18:06:30 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:49 EST