[R] help!! Java and R

Prof Brian D Ripley ripley at stats.ox.ac.uk
Wed May 10 11:09:15 CEST 2000


On Tue, 9 May 2000, Cheryl J Fernandes wrote:

> Hi
>  
>  I'm trying to run  the RGui program in WintNT from a Java
> application. i;m using runtime.exec()

You can't do that: Rgui is an Windows application and does not have a
command-line (few Windows programs do). Try using rterm, which does.

> It opens the program but after that nothing happens. After opening the
> program i'm passing some commands to R via java's process
> OutputStreamWriter. But it does NOT respond to any of the commands not
> even by giving an exception.

I suspect that you are just sending them to thin air, as there is no stdin
to connect to.  But the details will depend on your Java compiler and 
what exactly it does when asked to execute a Windows application.

> Coudl u please let me know if i can pass commandline commands to RGui from
> within Java or are there special API's that are available. I know for a
> fact taht Java does NOT have API's for R. It does have special interface
> API for major applications like C, Excel, MS-Word

Is C an application?  By the way, Java may not have APIs for R, but in the
Omegahat project there is a prototype R-Java interface.

R for Windows is embeddable: see the examples in the front-ends directory
in the source code. The cleanest way to do this to write a small C
interface that you can (I presume) link or load into your Java program
and which drives the R DLL.  It should be very easy to modify the rtest.c
example to do so, but you will need a way to manage two-communication
better than in the code below.

> Any help would be greatly appreciated.  
> 
> Runtime  rt = Runtime.getRuntime();
> String strCmdTmp ="";
> strCmdTmp =  "Z:\\R\\rw1000\\bin\\Rgui ";
> 
> Process jproc=  rt.exec(strCmdTmp);
> OutputStreamWriter o = new OutputStreamWriter(jproc.getOutputStream());
> 
> o.write("a<-c(4,5)\n");
> o.write("mean(a)\n");
> o.write("quit(\"no\")\n");
> o.flush();
> 
> String line=null;
> 
> BufferedReader reader = new BufferedReader(new
> InputStreamReader(jproc.getInputStream()));
> while((line = reader.readLine())!=null)
> System.out.println(" The line is:  " +line); 
> 
> Thanks in advance
> Cheryl  Fernandes
> 
> 
> Cheryl Fernandes                 (Home): (312) 432 4396, (630) 834 3796 
> 1926 W Harrison Street,          (Office): (312) 996 4605        
> Medical Center Apartments,
> Apt# 1202,
> Chicago, IL 60612
> 
> email: cferna3 at uic.edu
>        cfernand at eecs.uic.edu
> 
> 
> 
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list