[R] A slight trap in read.table/read.csv.

Mike Prager mike.prager at noaa.gov
Mon Mar 8 23:17:34 CET 2010


Rolf Turner <r.turner at auckland.ac.nz> wrote:
> 
> I solved the problem by putting in a colClasses argument in my
> call to read.csv().  But I really think that the read functions
> are being too clever by half here.  If field entries are surrounded
> by quotes, shouldn't they be left as character?  Even if they are
> all F's and T's?
> 
> Furthermore using F's and T's to represent TRUE's and FALSE's is
> bad practice anyway.  Since FALSE and TRUE are reserved words it
> would make sense for the read function to assume that a field is
> logical if it consists entirely of these words.  But T's and F's
> .... I don't think so.
> 
> I would argue that this behaviour should be changed.  I can see no
> downside to such a change.
> 

I agree with you, Rolf, that this is horrid behavior. It is such
automatic devices that have made people hate (e.g.) Microsoft
Word with a passion. 

Yet, in R this is a designed-in bug (e.g., feature) that
probably can't be changed without making some legacy code not
work. But at least, T and F could be removed soon as synonms for
TRUE and FALSE. We have seen that "_" was removed as an
assignment operator, and the world did not crumble. The use of T
and F is no less error-prone, and possibly more.

The only immediate solution to this accretion of overly clever
behavior would be for someone to write new functions (say,
Read.csv) that didn't do all those conversions behind the
scenes. I'm not about to do that. Are you?

Best of luck!

-- 
Mike Prager, NOAA, Beaufort, NC
* Opinions expressed are personal and not represented otherwise.
* Any use of tradenames does not constitute a NOAA endorsement.



More information about the R-help mailing list