From ripley at stats.ox.ac.uk  Wed Aug 30 22:15:45 2006
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Wed, 30 Aug 2006 21:15:45 +0100 (BST)
Subject: [Rd] Suggestion for read.table()
In-Reply-To: <6769639.199881156968166072.JavaMail.root@vms070.mailsrvcs.net>
References: <6769639.199881156968166072.JavaMail.root@vms070.mailsrvcs.net>
Message-ID: <Pine.LNX.4.64.0608302110340.19806@gannet.stats.ox.ac.uk>

On Wed, 30 Aug 2006, gilescrane at verizon.net wrote:

> First, I compliment you all
> for such a useful project as R.
> 
> Suggestion:  If read.table() could
> take input from a character string,
> then one could write
> 
> raw=
> "  x   y  z
>    1   2  3
>    4   5  6
> "
> df = read.table(raw,head=TRUE)

'raw' is the name of a function in R, so not a good choice.

> Of course, one can
> cat() to write raw into a 
> temporary file,
> and read.table() from that file.

Yes, we have anonymous file connections for that.

> However, direct reading might be a good option?

See ?textConnection for how to do this.

inp <- "  x   y  z
    1   2  3
    4   5  6
"
read.table(textConnection(inp), header=TRUE)

The most common case is wanting to paste in, and we have "clipboard" for 
that (at least on Windows on X11: it would be a nice addition on Aqua).

-- 
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




[Rd] Suggestion for read.table()
Prof Brian Ripley