[Rd] read.table and strip.white

Uwe Ligges ligges@statistik.uni-dortmund.de
Wed, 31 May 2000 09:11:38 +0200


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, ...)
                                  ^^^^^^^^^^^^^^^^^^^^^^^



There is also a little bug in the "windows help" to read.table(.):

Usage
read.table(file, header = FALSE, sep = "", dec = ".", quote = "'",
                                                              ^^^ must
be: "\"'"
and both of
read.csv(file, header = TRUE, sep = ",", quote="", 

read.csv2(file, header = TRUE, sep = ";", quote="", dec=",", 

                                                ^^ must be: "\""

Looks like a general problem with a backslashes in "winhelp" (?).

If requested, I will create a bug report...

Regards,
Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._