Re: [R] Image from bytes streams

2005-08-16 Thread Earl F. Glynn
"Márcio de Medeiros Ribeiro" <[EMAIL PROTECTED]> wrote in message
news:<[EMAIL PROTECTED]>...
>My big problem is that my program reads the image before that its
>complete by the png() function. For instance, my graphic image has
>1000Kb. When R saves it into the hard disk, my Java program reads the
>file before the save operation completes (500Kb for example). So, I
>got only a part of the file and hence the image... :(
>
>One solution is read the image and search for a byte which represents
>the end of the file, but it depends on the image format...

Have you considered in R writing the file to a temporary name (see
?tempfile). When the file is complete, after the dev.off() in R as suggested
by Prof Ripley, you could rename the file [using file.name() in R]. Your
external program can now access the file without worrying about whether it
is complete, since the file appears not to exist until the whole file has
been written.

efg

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Image from bytes streams

2005-08-16 Thread Prof Brian Ripley

On Tue, 16 Aug 2005, Márcio de Medeiros Ribeiro wrote:


First, thank you very much for the answers...

I have used the png() function before for generate the image and then
capture its bytes.

My big problem is that my program reads the image before that its
complete by the png() function. For instance, my graphic image has
1000Kb. When R saves it into the hard disk, my Java program reads the
file before the save operation completes (500Kb for example). So, I
got only a part of the file and hence the image... :(

One solution is read the image and search for a byte which represents
the end of the file, but it depends on the image format...

So, how can I discover that R image save operation stored the complete
file into the hard disk?


When dev.off() completes and you get an R prompt back.

--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Re: [R] Image from bytes streams

2005-08-16 Thread Márcio de Medeiros Ribeiro
Hi,

First, thank you very much for the answers...

I have used the png() function before for generate the image and then
capture its bytes.

My big problem is that my program reads the image before that its
complete by the png() function. For instance, my graphic image has
1000Kb. When R saves it into the hard disk, my Java program reads the
file before the save operation completes (500Kb for example). So, I
got only a part of the file and hence the image... :(

One solution is read the image and search for a byte which represents
the end of the file, but it depends on the image format...

So, how can I discover that R image save operation stored the complete
file into the hard disk?

Thank you one more time!
-- 
Márcio de Medeiros Ribeiro
Graduando em Ciência da Computação
Departamento de Tecnologia da Informação - TCI
Universidade Federal de Alagoas - UFAL
Maceió - Alagoas - Brasil
Projeto ArCo - Arcabouço de Comunidades
Contato: +55 82 354-3358/9997-6794

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Image from bytes streams

2005-08-16 Thread Henrik Bengtsson
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)
 >
C:\>

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 
"Rplots.ps"; that's the file you want to read.  I bet you have a two 
page Rplots.ps 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)
plot(1)
dev.off()

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.

Cheers

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! :)

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Image from bytes streams

2005-08-15 Thread Márcio de Medeiros Ribeiro
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! :)
-- 
Márcio de Medeiros Ribeiro
Graduando em Ciência da Computação
Departamento de Tecnologia da Informação - TCI
Universidade Federal de Alagoas - UFAL
Maceió - Alagoas - Brasil
Projeto ArCo - Arcabouço de Comunidades
Contato: +55 82 354-3358/9997-6794

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html