From Kurt.Hornik@ci.tuwien.ac.at  Sat Sep  1 10:13:49 2001
From: Kurt.Hornik@ci.tuwien.ac.at (Kurt Hornik)
Date: Sat, 1 Sep 2001 11:13:49 +0200
Subject: [Rd] RFC: type conversion in read.table
In-Reply-To: <Pine.GSO.4.31.0108311309340.28183-100000@auk.stats>
References: <15247.32012.939118.454204@mithrandir.hornik.net>
 <Pine.GSO.4.31.0108311309340.28183-100000@auk.stats>
Message-ID: <15248.42701.52888.634703@mithrandir.hornik.net>

>>>>> Prof Brian D Ripley writes:

> On Fri, 31 Aug 2001, Kurt Hornik wrote:
>> > Prof Brian Ripley wrote:
>> >>
>> >> Currently read.table is rather limited in its type conversion.
>> >> The algorithm is
>> >>
>> >> 0) Read as character
>> >> 1) Try to convert to numeric. If that works, quit
>> >> 2) Convert to factor unless !as.is.
>> >>
>> >> I am thinking about adding more flexibility and more classes by the
>> >> following two changes.
>> >>
>> >> A) Anticipating the arrival of classes for all R objects, add an
>> >> argument say `colClasses' that allows the user to specify the desired
>> >> class for every column.  This could default to "auto", or NA if people
>> >> think "auto" might be a relevant class name one day.
>> >>
>> >> The effect would be equivalent to running
>> >>
>> >> data[[i]] <- as(data[[i]], colClasses[i])
>> >>
>> >> instead of
>> >>
>> >> data[[i]] <- type.convert(data[[i]], as.is = as.is[i], dec = dec)
>> >>
>> >> except that standard classes such as "numeric", "factor", "logical",
>> >> "character" would be dispatched directly, and argument "dec" would be
>> >> consulted where appropriate.
>> >>
>> >> colClasses = "character" would suppress all conversions, which cannot
>> >> currently be done.
>> 
>> Just a small remark.  I would prefer `NA' to "auto" (or "unknown").  May
>> be too late to change this now :-)

> Anything can be changed up to 1.4.0 release.  In particular, the
> present code will have to be changed unless as() is in base by then.

Ok.  Can I formally propose to use NA then?  (I guess this convention
could be useful in similar situations as well.)

>> I would also be happier if we did not refer to the variables explicitly
>> as `columns'.  (This sounds a bit stupid from the person who wrote
>> write.table and introduced arguments `row.names' and `col.names'.
>> Although, at least one of these was modelled after an existing
>> function).  E.g. something like
>> 
>> read.table(......, caseNames, varNames, varClasses, .....)
>> 
>> would be nice ...

> The problem is that what is being referred to *is* columns and not
> variables.  If you have row names on the file, the numbering is
> different.  So it matters to use sufficiently precise terminology.

Right.  Convinced now.

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


[Rd] RFC: type conversion in read.table
Kurt Hornik