Skip to content
Prev 3428 / 398500 Next

Java interface to R

Richard PIper wrote:
To try and answer my own question. It does seem to possible to 
connect to the R process as follows:

	Process p  = Runtime.getRuntime().exec("R --slave");

	OutputStreamWriter o = new OutputStreamWriter(p.getOutputStream());
	o.write("data(sleep)\n");
	o.write("summary(sleep$extra)\n");
	o.write("mean(sleep$extra)\n");
	o.write("quit(\"no\")\n");
	o.flush(); 


        BufferedInputStream buffer =
          new BufferedInputStream(p.getInputStream());
        DataInputStream commandResult =
          new DataInputStream(buffer);
 etc ..

It seems to work quite well with limited testing


Richard