[Rd] read.csv

Gabor Grothendieck ggrothendieck at gmail.com
Sun Jun 14 22:37:51 CEST 2009


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"))



More information about the R-devel mailing list