[R] Controlling R from Java

Warnes, Gregory R gregory_r_warnes at groton.pfizer.com
Thu Dec 14 16:20:27 CET 2000


Duncan's reply is the best long term solution, but a simple and quick hack
is to append something like 

	; cat(paste("\n<DO","NE\n>",sep=""))

to the end of each commend.  This way, when the command finishes, there is a
nice token ("<DONE>") to grab.  (The paste bit is to that you don't match
<DONE> from the command string if it gets echoed for some reason.)

IE:

	atlas% echo ' ls(); cat(paste("\n<DO","NE>\n",sep="") ) ' | R
--no-save

	R : Copyright 2000, The R Development Core Team
	Version 1.1.1  (August 15, 2000)
	[...]
	[Previously saved workspace restored]

	>  ls(); cat(paste("\n<DO","NE>\n",sep="") ) 
	[1] "beta.binom"                      "devs"

	[3] "log.beta.binomial.beta.binomial" "p"

	[5] "x"                              

	<DONE>


-Greg


> -----Original Message-----
> From: Marc Grushcow [mailto:Marc.Grushcow at ntt.ca]
> Sent: Tuesday, December 12, 2000 3:38 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Controlling R from Java
> 
> 
> I'd like to run R (LINUX) under Java. I can create the 
> process and connect to
> stdin and stdout. I can send commands in and get output back. 
>  I don't know how
> to determine when the output is complete - there is no 
> trailing "prompt".
> 
> For example, if I send "ls()\n" what I get back is:
> > ls()
> character(0)
> 
> Each of the above two lines is terminated with a 0x0A. I 
> would have expected
> (liked)...
> ls()
> character(0)
> > 
> 
> Then I could parse for the "\n> " and know when the output is 
> complete. The
> problem with checking for data availability on the input 
> stream is that it is
> unreliable. R's output buffer might flush unpredictably 
> and/or the task
> switching OS might cause R to stop after one buffer is full 
> but before another
> is completed.  In any case, it is the usual problem of one 
> program trying to
> parse another's output in a time sharing environment.
> 
> I'm sure that this problem has been solved before.  Any 
> suggestions would be
> appreciated.
> 
> Thanks
> Marc
> -- 
> =.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.
> mailto:Marc.Grushcow at NTT.ca		http://www.NTT.ca
> =.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
> -.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> _._._._._._._._._
> 
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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