[R] "Pipelining" programs in R
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri May 19 08:03:55 CEST 2006
You can use system() or pipe() and friends. This is covered in Section
5.1 of `Writing R Extensions'.
Perhaps the simplest way is to something like
tmp <- tempfile()
zz <- file(tmp, "w")
# write the input script to zz, e.g. via cat
close(zz)
res <- system(paste("myprog <", tmp), intern = TRUE)
and then parse the output from the character vector 'res'.
If you have a Unix-like OS and understand pipes, fifos and sockets you can
also use those: see ?pipe. (With a higher degree of understanding you can
use some of these on Windows NT.)
It would have been very helpful to have known your OS, a piece of
information the posting guide asked for. (Since you talk about 'open'ing
an executable, I surmise you are not familiar with traditional OSes which
'run' programs.)
On Thu, 18 May 2006, 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.
>
> Any advice will be greatly appreciated!
>
> Thanks,
> Dan Rabosky
>
>
>
> Dan Rabosky
> Department of Ecology and Evolutionary Biology
> 237 Corson Hall
> Cornell University
> Ithaca, NY14853-2701 USA
> web: http://www.birds.cornell.edu/evb/Graduates_Dan.htm
>
> ______________________________________________
> R-help at 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
>
--
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 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list