Re: [R] R more Unix-like?

From: Robert Citek <>
Date: Thu 11 May 2006 - 16:39:20 EST

On May 10, 2006, at 10:40 PM, Gabor Grothendieck wrote:

> Try this on Windows or the corresponding ls command on UNIX:
> readLines(pipe("cmd /c dir"))

I tried this from within R:

   readLines(pipe("bash -c ls"))

and this from the command line:

   $ echo 'readLines(pipe("bash -c ls"))' | R -q --no-save

both of which produced a listing of the current folder. So one strategy would be to build up the command pipe within the R program:

   $ echo 'for (i in readLines(pipe("seq 1 10")))

           print(sprintf("foo %s", i))' | R

While not exactly the solution I was looking for, it did allow me to do perform some simple summary stats on one field in a large data set:

$ wc -l ../data/foo.txt
13628161 ../data/foo.txt

$ echo 'summary(as.numeric(readLines(pipe("< ../data/foo.txt cut -f 10 | tail +2")))); proc.time()' | R

R > summary(as.numeric(readLines(pipe("< ../data/foo.txt cut -f 10 | tail +2")))); proc.time()

    Min. 1st Qu. Median Mean 3rd Qu. Max.    114.5 862.8 1316.0 2030.0 2111.0 65540.0 [1] 59.323 0.964 60.283 8.324 8.324

All that in about a minute. Very nice.

- Robert
Help others get OpenSource software. Distribute FLOSS for Windows, Linux, *BSD, and MacOS X with BitTorrent mailing list PLEASE do read the posting guide! Received on Thu May 11 16:45:57 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 11 May 2006 - 18:10:04 EST.

Mailing list information is available at Please read the posting guide before posting to the list.