[R] perl advice

Prof Brian D Ripley ripley at stats.ox.ac.uk
Tue Dec 7 00:25:07 CET 1999


On Mon, 6 Dec 1999, Guido Masarotto wrote:

> On Mon, Dec 06, 1999 at 05:12:44PM -0500, John D. Barnett wrote:
> > Hello-
> > 
> > Does anyone have a recommendation on how to call R from perl?  I'm using
> > the IPC::Open2 module, and running R with the --slave and --quiet
> > options.  The problem is that I can't predict how many lines of output I
> > should try to read for each command-- if any!
> > 
> > The ultimate goal is to use perl to provide a form-driven web interface,
> > but have R do the underlying calculations.
> > 
> 
>   A trick that I have used sometimes from tcl/tk is to redefine the
>   prompt to some funny string (sending to the controlled process
>   a 'option(prompt=...) command at the beginning) and then wait
>   for the prompt on the output. If I remember also ESS
>   works in a  probably less weaker but similar approach (i.e., it
>   waits for a particular regular expression on the standard output
>   of the R process).
>   Hoping this can help,

Yes, ESS uses something like that. But, Programming Perl, p.345, warns you
not to use IPC::Open2 for this purpose, because of buffering, but Comm.pl
(from CPAN) instead.  Emacs does use pseudo-ptys (on Unix, and tricks on
Win32) to overcome the buffering problem. I am not sure that R always
flushes its buffers, as although Rprintf seems to do so if it thinks it has
an output file, R_WriteConsole does not.  (Crashes in batch jobs do
sometimes seem to have incomplete output on the output file.)

-- 
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