From Prof Brian Ripley <ripley@stats.ox.ac.uk>  Wed May 31 17:43:11 2000
From: Prof Brian Ripley <ripley@stats.ox.ac.uk> (Prof Brian Ripley)
Date: Wed, 31 May 2000 17:43:11 +0100 (BST)
Subject: [Rd] read.table and strip.white
Message-ID: <200005311643.RAA09975@toucan.stats.ox.ac.uk>


> Date: Wed, 31 May 2000 09:11:38 +0200
> From: Uwe Ligges <ligges@statistik.uni-dortmund.de>
> X-Accept-Language: en
> To: R-devel <r-devel@stat.math.ethz.ch>
> CC: busse@statistik.uni-dortmund.de, Joerg Guettner <guettner@gmx.de>
> Subject: [Rd] read.table and strip.white 
> 
> Hi!
> 
> I want to read data (using read.table(.)) from a file like:
> 
>   "col1", "col2", "col3"
>   1, 1, 1
>   2, 2, 2
> 
> 
> But the white spaces are interpreted:
> 
>   x <- read.table("filename", header=TRUE, sep=",")  ## or read.csv(...)
>   colnames(x)
> [1] "col1"  " col2" " col3"
>              ^       ^ 
> 
> So I would like to pass an argument like strip.white=TRUE (as in
> scan(.)) to read.table(.) .
> If this is nonsense, please let me know.
> 
> 
> At my first look only three lines (and documentation) must be changed:
> 
> l. 1-3 add: function(..., strip.white=FALSE, ...)
>                           ^^^^^^^^^^^^^^^^^
> l. 16 + 35 add:  ... <- scan(..., strip.white=strip.white, ...)
>                                   ^^^^^^^^^^^^^^^^^^^^^^^
> 

I was rather surprised here, and this is not what the prototype does:

  .col1. .col2. .col3. 
1      1      1      1
2      2      2      2

Should not strip.white be true for the header line?
That's what the prototype does:

toucan% cat fff
  col1, col2, col3
  a, 1, 1
  b, 2, 2

Splus
> x <- read.table("fff", header=TRUE, sep=",", row.names=NULL)
> x
  col1 col2 col3 
1    a    1    1
2    b    2    2
> as.matrix(x)
   col1 col2 col3 
1 "  a" "1"  "1" 
2 "  b" "2"  "2" 

You can always quote on the header line if you really want names
with leading spaces.

I think we could add strip.white for use in the body, quite easily.

Any comments?


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


[Rd] read.table and strip.white
Prof Brian Ripley