[Rd] Suggestion for comments in data files (i.e. read.table)

Prof Brian D Ripley ripley@stats.ox.ac.uk
Tue, 23 May 2000 07:05:37 +0100 (BST)


On Tue, 23 May 2000, Telford Tendys wrote:

> I realise that there is an existing system for documenting datasets
> but what I would like is to be able to whack a few lines of commentary
> at the top of a file which contains data -- not full documentation but
> just an outline for myself to remind me of what I was doing or what
> settings I was using, etc.
> 
> I was thinking that the read.table() function might be extended to
> support an option allowing it to throw away lines that begin with
> the # character (same comment character as R source, shell script, perl, etc)
> thus allowing data files with comments added to them. For example:
> 
> ------------------------------------->8---
> # Testing the force of my linear motor
> # v = supply voltage (reading from built-in meter on bench supply)
> # x = distance of movement (NA indicates that bar was dropped)
> # m = mass of bar
> "v" "x" "m"
>  1   2   3
>  4   5   6
>  7   8   9
> # I might have bumped the table for this one
> 10  NA  12
> 
> etc...
> ------------------------------------->8---
> 
> Then you can load it up with:
> 
> mytable <- read.table( "data", header=TRUE, comment=TRUE )
> 
> and then proceed as normal.
> 
> I'm sure it would be a very small change, if other people think
> it might be useful then I'll try and make a patch to support it.

I am sure it is not `a very small change', I'm afraid.  Basically, input is
not done in a line-oriented way. read.table uses scan and count.fields.  
Both are internal functions that work at a char-by-char level.  You will
need to add logic to skip lines, and for your rule that means adding logic
to know that # is first in a line.

My suggestion would be to allow # anywhere on the line to skip the
rest of the line, and to make sure that # inside quotes did nothing.


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