Hi, how can I use R in a pipline like this $ ./generate-data | R --script-file=Script.R | ./further-analyse-data > result.dat Assume a column based output of ./generate-data, e.g. something like: 1 1 1 2 4 8 3 9 27 4 16 64 The R commands that process the data should come from Script.R and should print to stdout (Script.R could for example calculate the square of every entry or calculate the mean of the columns, ...) The output should be printed to stdout, such that further-analyse-data can use the output. Can some R expert code that for me please? I would be very happy. I am also happy about information how to do that myself although I dont think I know enough to do that myself. Thank you for your consideration, Micha -- GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS. Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail
This is one of the things that 'Rscript' is for: see 'An Introduction to R' (section B.4 in the HTML version, http://cran.r-project.org/doc/manuals/R-intro.html#Scripting-with-R). You haven't even told us your version of R or OS (see the posting guide): you need R >= 2.5.0 for this. But your 'example' would be ./generate-data | Rscript Script.R | ./further-analyse-data > result.dat On Thu, 7 Jun 2007, mw-u2 at gmx.de wrote:> Hi, > > how can I use R in a pipline like this > > $ ./generate-data | R --script-file=Script.R | ./further-analyse-data > result.dat > > Assume a column based output of ./generate-data, e.g. something like: > 1 1 1 > 2 4 8 > 3 9 27 > 4 16 64 > > The R commands that process the data should come from Script.R and > should print to stdout (Script.R could for example calculate the square > of every entry or calculate the mean of the columns, ...) > > The output should be printed to stdout, such that further-analyse-data > can use the output. > > Can some R expert code that for me please? I would be very happy. I am > also happy about information how to do that myself although I dont think > I know enough to do that myself. > > Thank you for your consideration, > > Micha >-- 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
On 7 June 2007 at 14:27, mw-u2 at gmx.de wrote: | how can I use R in a pipline like this | | $ ./generate-data | R --script-file=Script.R | ./further-analyse-data > result.dat The 'r' in our 'littler' package can do that. One example we show on the littler webpage is $ ls -l /boot | awk '!/^total/ {print $5}' | \ r -e 'fsizes <- as.integer(readLines()); print(summary(fsizes)); stem(fsizes)' We use R's readLines to read from stdin, and you can of course also have r 'in the middle' if you take care of the output generated -- which our example doesn't do as it prints straight to screen. Dirk -- Hell, there are no rules here - we're trying to accomplish something. -- Thomas A. Edison