[Rd] two-way communication using Unix pipes

Barry Rowlingson B.Rowlingson at lancaster.ac.uk
Wed Nov 16 16:58:26 CET 2005


Jonathan Callahan wrote:

> Can someone please explain to me exactly what R is doing with the the
> standard IO handles and whether or not there is any simple way to convince
> it to behave as if it were talking to a user at the other end of a keyboard
> and terminal? I've already tried '--no-readline' but that doesn't solve my
> problem.
> 

This little noddy example works for me:

#!/usr/bin/perl

use FileHandle;
use IPC::Open2;

$pid=open2(*Reader, *Writer, "R --no-save");
print Writer "x=runif(10);print(mean(x))\n";
while($got=<Reader>){
     print "Got ".$got;
}

Of course, without the \n in the command string it doesnt work at all, 
but I dont see any problems with R reading from stdin and writing to 
stdout....

This is on a Linux box, I dont think you mentioned an OS or platform...

Baz



More information about the R-devel mailing list