From ggrothendieck at gmail.com  Sun Jun 14 22:37:51 2009
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Sun, 14 Jun 2009 16:37:51 -0400
Subject: [Rd] read.csv
In-Reply-To: <XFMail.090614212124.Ted.Harding@manchester.ac.uk>
References: <971536df0906141156j78b5570ajf08257c88098d7d8@mail.gmail.com> 
	<XFMail.090614212124.Ted.Harding@manchester.ac.uk>
Message-ID: <971536df0906141337i148c3893t6a08afe376c5151c@mail.gmail.com>

On Sun, Jun 14, 2009 at 4:21 PM, Ted
Harding<Ted.Harding at manchester.ac.uk> wrote:
> Or am I missing something?!!

The point of this is that the current behavior is not desirable since you can't
have quoted numeric fields if you specify colClasses = "numeric" yet you
can if you don't.  The concepts are not orthogonal but should be.  If you
specify or not specify colClasses the numeric fields ought to be treated
the same way and if the documentation says otherwise it further means
there is a problem with the design.

One could define their own type quotedNumeric as a workaround
(see below) but I think it would be better if specifying "numeric" or
not specifying
numeric had the same effect.  The way it is now the concepts are intertwined
and not orthogonal.

library(methods)
setClass("quotedNumeric")
setAs("character", "quotedNumeric",
  function(from) as.numeric(gsub("\"", "", from)))
Lines <- 'A,B
"1",1
"2",2'
read.csv(textConnection(Lines), colClasses = c("quotedNumeric", "numeric"))



[Rd] read.csv
Gabor Grothendieck