From murray at stokely.org  Thu Apr 17 22:31:46 2014
From: murray at stokely.org (Murray Stokely)
Date: Thu, 17 Apr 2014 16:31:46 -0400
Subject: [Rd] type.convert and doubles
In-Reply-To: <CAP01uRmdnTUgDH=sNryx9=w5Rtmw3b+8KiZOWPg48r6rc86ssQ@mail.gmail.com>
References: <3736EC2D-7360-4AF6-BF96-5A2DF3D3EF14@warnes.net>
	<326FE12B-D6FE-471B-9E0C-10BEC0584DB7@r-project.org>
	<534860CC.2090206@gmail.com>
	<17B09E7789D3104E8F5EEB0582A8D66F0129CED9FD8C@MSGRTPCCRF2WIN.DMN1.FMR.COM>
	<CAECWziJq92keAD2sHHE7ky6CHhqatrBOONq_Vf18AHJ8GActZw@mail.gmail.com>
	<CAP01uRmdnTUgDH=sNryx9=w5Rtmw3b+8KiZOWPg48r6rc86ssQ@mail.gmail.com>
Message-ID: <CAECWziKLBRjRNpneVJ2hNbTG3jF2ec6GeF9m+1S092WoufCdiQ@mail.gmail.com>

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



[Rd] type.convert and doubles
Murray Stokely