[R] "Pipelining" programs in R

Jan T. Kim jtk at cmp.uea.ac.uk
Fri May 19 12:21:10 CEST 2006


On Thu, May 18, 2006 at 11:50:24PM -0400, Dan Rabosky wrote:
> 
> Hello...
> 
> I would like to use R for 'pipelining' data among several programs.  I'm 
> wondering how I can use R to call another program, feed that program a set 
> of parameters, and retrieve the output.
> 
> E.g., I have an executable that, when opened, prompts the user to enter a 
> set of parameters.  The program then executes & prompts the user for the 
> name of an output file.  I need to run this program on a large batch of 
> parameters, such that it would clearly be desirable to automate the 
> process.  Is there a straightforward way to do this?  I can't find any 
> online documentation addressing this topic, but perhaps I've not been 
> looking in the right place.
> 
> In pseudocode, supposing I have a large array of parameters in R:
> 
> For each set of parameters
>          -Open Program.
>          -Enter Parameters.
>          -Cause program to execute (typically done by simply entering " \n 
> " after manually entering parameters).
>          -Enter name of output file.
>          -Close program.

If your program gets all the input it requires from the command line,
you might use the pipe function, as in

    f <- pipe("ls -l");
    l <- readLines(f);

However, your executable seems to expect its input via its standard input
and you want to read the output it writes to its standard output. To my
knowledge, this is not possible with R. I've written some stuff to add
such functionality to R, this is available from

    http://www2.cmp.uea.ac.uk/~jtk/software/

The filterpipe patch is against an older version of R, though.

Best regards, Jan
-- 
 +- Jan T. Kim -------------------------------------------------------+
 |             email: jtk at cmp.uea.ac.uk                               |
 |             WWW:   http://www.cmp.uea.ac.uk/people/jtk             |
 *-----=<  hierarchical systems are for files, not for humans  >=-----*




More information about the R-help mailing list