From jlongmat@coh.org  Fri Feb  1 22:54:10 2002
From: jlongmat@coh.org (jlongmat@coh.org)
Date: Fri, 1 Feb 2002 23:54:10 +0100 (MET)
Subject: [Rd] comment.char in read.fwf (PR#1297)
Message-ID: <200202012254.XAA23376@pubhealth.ku.dk>

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


[Rd] comment.char in read.fwf (PR#1297)
jlongmat@coh.org