[Rd] type.convert and doubles

Murray Stokely murray at stokely.org
Thu Apr 17 22:31:46 CEST 2014


On Thu, Apr 17, 2014 at 2:35 PM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> Only if you knew that that column was supposed to be numeric. There is

The columns that are "supposed" to be numeric are those that can fit
into a numeric data type.  Previously that was not always the case
with columns that could not be represented as a numeric erroneously
coerced into a truncated/rounded numeric.

> nothing in type.convert or read.table to allow you to override how it
> works (colClasses only works if you knew which columns are which in
> the first place) nor is there anything to allow you to know which
> columns were affected so that you know which columns to look at to fix
> it yourself afterwards.

You want a casting operation in your SQL query or similar if you want
a rounded type that will always fit in a double.  Cast or Convert
operators in SQL, or similar for however you are getting the data you
want to use with type.convert().  This is all application specific and
sort of beyond the scope of type.convert(), which now behaves as it
has been documented to behave.

In my code for this kind of thing I have however typically introduced
an option() to let the user control casting behavior for e.g. 64-bit
ints in C++.  Should they be returned as truncated precision numeric
types or the full precision data in a character string representation?
 In the RProtoBuf package we let the user specify an option() to
specify which behavior they need for their application as a shortcut
to just always returning the safer character representation and making
them coerce to numeric often.

            - Murray



More information about the R-devel mailing list