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) Of course, one can cat() to write raw into a temporary file, and read.table() from that file. However, direct reading might be a good option? Hope this is useful. Cordially Giles Crane gilescrane at verizon.net
Try this:> raw+ " x y z+ 1 2 3 + 4 5 6 + "> read.table(textConnection(raw), header = TRUE)x y z 1 1 2 3 2 4 5 6 On 8/30/06, gilescrane at verizon.net <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) > > Of course, one can > cat() to write raw into a > temporary file, > and read.table() from that file. > However, direct reading > might be a good option? > > Hope this is useful. > Cordially > Giles Crane > gilescrane at verizon.net > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
Hi Giles, x = "x y z\n1 2 3\n4 5 6" res = read.table(textConnection(x), header=TRUE) will do. See also http://cran.r-project.org/doc/manuals/R-data.html Best wishes Wolfgang Huber EMBL-EBI, Cambridge UK 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) > > Of course, one can > cat() to write raw into a > temporary file, > and read.table() from that file. > However, direct reading > might be a good option? > > Hope this is useful. > Cordially > Giles Crane > gilescrane at verizon.net
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
On Thu, 31 Aug 2006, Simon Urbanek wrote:> > On Aug 30, 2006, at 10:15 PM, Prof Brian Ripley wrote: > > >On Wed, 30 Aug 2006, gilescrane at verizon.net wrote: > > > > >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). > > > > On Mac OS X (Aqua or cmd line) you can use clipboard input like this: > read.table(pipe("pbpaste")) > It seems to be quite popular especially in conjunction with Excel...Yes, I know (I even documented in ?connections). What would be nice is if read.table("clipboard") worked as it does on the other platforms. -- 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