read.table ignores first 5 lines (PR#1885)

Russ Lenth russell-lenth@uiowa.edu
Thu, 08 Aug 2002 10:35:37 -0500


Gentlemen,

This is informative; thanks.  Following Prof. Ripley's comment, I confirmed that
a command like:

	read.table (textConnection(readLines()), head=T)

ALMOST works for my purposes.  On our HP-UX installation of R 1.5, I can enter
(or paste) the data, then press Ctrl-D, and I've got what I want.  Under
Windows, however, I could not find a way to signal the end of the file (I tried
Ctrl-Z, Ctrl-D, Ctrl-C); so in that case it only works if I provide the "n"
argument for readLines.  I'm surprised that Ctrl-Z doesn't work.

I also confirmed that it's possible to have a statement like

	if (file == stdin()) ...

so, if it's possible to resolve the end-of-file issue, there is a way to make
read.table do what I want (if only in my own custom version of read.table).

Russ
-- 
Russell V. Lenth -- Department of Statistics & Actuarial Science      
The University of Iowa -- Iowa City, IA 52242  USA 
Tel (319)335-0814 -- FAX (319)335-3017
mailto:Russell-Lenth@uiowa.edu - http://www.stat.uiowa.edu/~rlenth/



ripley@stats.ox.ac.uk wrote:
> 
> On Thu, 8 Aug 2002, Liaw, Andy wrote:
> 
> > Prof. Ripley,
> >
> > In that case, is it possible to check for such things and give an error in
> > read.table?  (Or perhaps warn against such misuse in the help file...)
> 
> It is now warned about in the help file.
> 
> It's impossible to give a warning, as it is scan behaving differently
> in one particular case, not going through the connections machinery so it
> can give prompts.  On the other hand, at R level we don't know what
> stdin() is.
> 
> The only way I see to fix this is inside scan().  That might be possible,
> On the other hand, there really are easy workarounds if all the input is
> available: just use readLines to a character vector and call read.table on
> the result.
> 
> > read.table(textConnection(readLines()), header=T)
> >  a b c
> > 1 2 3
> > 4 5 6
> > 7 8 9
> > 10 11 12
> > 13 14 15
> > 16 17 18
> > 19 20 21
> > 22 23 24
> >
> >    a  b  c
> 1  1  2  3
> 2  4  5  6
> 3  7  8  9
> 4 10 11 12
> 5 13 14 15
> 6 16 17 18
> 7 19 20 21
> 8 22 23 24
> 
> where I pasted in the first block (with the > prompts).  Rgui won't work
> with this, though, another way in which stdin() is special.
> 
> --
> Brian D. Ripley,                  ripley@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 272860 (secr)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._