Skip to content

perl advice

5 messages · Guido Masarotto, Jim Robison-Cox, Brian Ripley +1 more

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

Thanks for any help!

-John Barnett

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Mon, Dec 06, 1999 at 05:12:44PM -0500, John D. Barnett wrote:
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,

  guido
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Mon, 6 Dec 1999, John D. Barnett wrote:
Before you reinvent the wheel, look at Jeff Banfield's Rweb:
http://www.math.montana.edu/Rweb/

  You might contact him directly:  jeff at math.montana.edu 
(I know he doesn't read R-help.) if you have more questions.

 Jim

Jim Robison-Cox               ____________    
Department of Math Sciences  |            |       phone: (406)994-5340
2-214 Wilson Hall             \   BZN, MT |       FAX:   (406)994-1789
Montana State University       |  *_______|
Bozeman, MT 59717-2400          \_|      e-mail: jimrc at math.montana.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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Mon, 6 Dec 1999, Guido Masarotto wrote:

            
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.)
#
Thanks; this is all very helpful.

I looked into Comm.pl, but had problems using it.  I found a message somewhere
saying that Comm.pl was fairly specific to SunOS 4/5; there's a newer perl
module
with similar functionality, Expect.pm

I've already written a routine to parse R output produced by dump(), but now
that
I'm able to interact directly, I'd like to parse R's normal output-- unless
there's a
way that I can send dump's output to STDOUT.

Thanks again!
Prof Brian D Ripley wrote:

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