[R] Process to both write to and read from (pipe/fork)?

From: Jan T. Kim <jtk_at_cmp.uea.ac.uk>
Date: Wed 02 Feb 2005 - 00:53:05 EST

Dear all,

I would like to start a process from an R program in such a way that I can both feed input into the process and read the process's output. It seems that in R, I can have a pipe for writing into another process's input or a pipe for reading from another process's output, but not both.

Doing both necessitates forking, such that the child can start the external process and feed that with some input, and the parent can read the output from the external process. Additionally, this requires obtaining a plain pipe, i.e. one with an input handle (for writing to) and an output handle (for reading from) prior to forking, so the child can connect the external process's stdout to the input handle and the parent can read that from the output handle.

My problem is that I cannot find a way in R to set up such a pipe.

For forking, I've found the fork package, but I can't seem to get a pipe. I know about the pipe function in the base package, but it seems to me that that is an interface to popen(2), rather than to pipe(2) (see attached C source). At least, I can't seem to get anything else but a popen equivalent from it. I've looked for a pipe package, for pipe in the fork package, and googled around, to no avail.

For illustrating what I'd like to do, I attach a C program that replicates the pipe example from the base docs, with the difference that the input data to be processed with sed are present in the program rather than in a file.

I start to feel silly and stupid for being unable to figure out such a basic thing. Thanks in advance for any help -- RTFMs very welcome.

Best regards, Jan

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

______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Received on Tue Feb 01 23:06:47 2005

This archive was generated by hypermail 2.1.8 : Wed 02 Feb 2005 - 01:18:55 EST