RE: [R] Can R read data from stdin?

From: Hayashi Soichi - shayas <>
Date: Sat 10 Jul 2004 - 07:41:48 EST

Thanks! That's what I was wanted to know.

Also, is there a similar way I can do read.table from a pipe?

For example, if there is a command that I am running to generate the datasource, I want to read that data as it comes..


-----Original Message-----
From: Aaron J. Mackey [] Sent: Friday, July 09, 2004 4:10 PM
To: Tony Plate
Cc:; Hayashi Soichi - shayas Subject: Re: [R] Can R read data from stdin?

I think the original poster wanted to read data from stdin, not execute an entire script from stdin; this works on many UNIX-like systems:

d <- read.table("/dev/stdin", header=F);

Otherwise, for code, you can simply pipe (or redirect) to R from the shell:

% R --vanilla --slave < input > outfile


On Jul 9, 2004, at 4:34 PM, Tony Plate wrote:

> The easiest way would probably be to do the hack of creating a
> temporary file to hold stdin, then call R to process that file. That
> would be easy to do in a shell script.
> If this really won't suffice, this older message might lead to
> something useful:
>> Rd] R scripting patches for R-1.8.0
>> Neil McKay mckay at
>> Thu Oct 16 20:30:20 MEST 2003
>> Previous message: [Rd] data() misbehaving inside a function
>> Next message: [Rd] R scripting patches for R-1.8.0
>> Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
>> ----------------------------------------------------------------------
>> ----------
>> I've updated my scripting patches to R-1.8.0. These patches
>> allow you to write shell scripts in R (at least on *nix systems)
>> by putting
>> #!/path/to/R.bin --script
>> on the first line of the script file. If you're interested
>> in the patches, e-mail me at
>> mckay at
>> --
>> Neil D. McKay, Mail Code 480-106-359 Phone: (586)986-1470
>> (GM:8-226-1470)
>> Manufacturing Systems Research Lab FAX: (586)986-0574
>> (GM:8-226-0574)
>> GM Research & Development Center Internet e-mail: mckay at
>> 30500 Mound Road
>> Warren, Mich. 48090
> At Friday 02:17 PM 7/9/2004, Hayashi Soichi - shayas wrote:
>> Is there anyway I can write a script which feed input datasource from
>> stdin
>> and let R process it (maybe frequency report) then output the report
>> to
>> stdout?
>> I can't seem to find much info on documentation or FAQ on this topic.
>> Thanks!
>> Soichi Hayashi

The information contained in this communication is confidential, is intended only for the use of the recipient named above, and may be legally privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication is strictly prohibited.
If you have received this communication in error, please re-send this communication to the sender and delete the original message or any copy of it from your computer system. Thank You. mailing list PLEASE do read the posting guide! Received on Sat Jul 10 07:50:01 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 02:35:27 EST