[Rd] comment.char in read.fwf (PR#1298)

jlongmat@coh.org jlongmat@coh.org
Fri, 1 Feb 2002 23:54:35 +0100 (MET)


Full_Name: Jeffrey Longmate
Version: Version 1.4.0 Patched (2002-01-23)
OS: Windows NT 4.0
Submission from: (NULL) (151.152.101.44)


In read.fwf, ... args are passed to read.table, as stated in the documentation. 
However, passing comment.char in this manner is defeated by the call to scan
that precedes the call to read.table.  The problem is that scan has a default
comment.char="#", and read.fwf doesn't pass ... to scan.  A simple solution is
to put comment.char="" in the call to scan, so that the entire string is passed
to read.table.  That seems to be the intended purpose of the call to scan
anyway. 

Here is an example where I'd like to specify comment.char="" to turn off the
interpretation of comments altogether.
Contents of file test.dat:
123ABC123
123#3 123
123XYZ123

> read.fwf("test.dat", widths=c(3,3,3), sep="\t", comment.char="")
   V1  V2  V3
1 123 ABC 123
2 123  NA  NA
3 123 XYZ 123

Replacing this assignment in read.fwf:
    raw <- scan(file, what = "", sep = "\n", quote = "", quiet = TRUE, n = n)
with this in Xread.fwf:
   raw <- scan(file, what = "", sep = "\n", quote = "", quiet = TRUE,
      n = n, comment.char="")
we get:
Xread.fwf("test.dat", widths=c(3,3,3), sep="\t", comment.char="")
   V1  V2  V3
1 123 ABC 123
2 123 #3  123
3 123 XYZ 123

as we should.




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