[R] Header in read.table() function

Marc Schwartz marc_schwartz at me.com
Wed Feb 3 22:58:42 CET 2010


My recommendation would be to leave the default behavior in place. With multiple '-' characters in your imported variable (object) names, you are not only asking to get bitten, but are indeed begging the R Gods to throw lightning bolts in your general direction.

Using ABCD.002.234.01D and similar will save you many headaches. If you need to pretty print out something after the fact, you can always adjust column headers and such using appropriate functions for formatted output.

This general approach is called defensive programming and is intended to help you avoid the inevitable errors that will creep into your code without your realizing it...until it is too late.

HTH,

Marc Schwartz


On Feb 3, 2010, at 3:48 PM, Paul Evans wrote:

> Hi All,
> 
> I hadn't realized the 'a-1' will open such a can of worms!
> Actually, the header elements will look something like 'ABCD-002-234-01D' (instead of 'a-1'). I get the files from somwhere else, so I cannot change how the input file is. 
> Should I go ahead with the check.names=FALSE option?
> 
> 
> 
> ________________________________
> From: Erik Iverson <eriki at ccbr.umn.edu>
> 
> Cc: r-help at stat.math.ethz.ch
> Sent: Wed, February 3, 2010 4:27:11 PM
> Subject: Re: [R] Header in read.table() function
> 
>> If you're data.frame had a
>> column named 'a', what should
>> 
>>> mm$a-1
>> 
>> do? Print out mm$a-1, or subtract 1 from mm$a ?  If you want your
>> original matrix back (i.e., object of class matrix), you could just use
>> save/load functions.
> 
> David found a way to get this in.  I read the file in, converted to 
> numeric.
> 
> mm$a-1 subtracts 1 from a,
> 
> and using
> mm$`a-1` prints out the a-1 column...
> 
> I stand corrected, and agree that it is probably not worth the trouble.



More information about the R-help mailing list