[Rd] type.convert and doubles

Paul Gilbert pgilbert902 at gmail.com
Fri Apr 11 23:38:20 CEST 2014



On 04/11/2014 01:43 PM, Simon Urbanek wrote:
> Greg,
>
> On Apr 11, 2014, at 11:50 AM, Gregory R. Warnes <greg at warnes.net>
> wrote:
>
>> Hi All,
>>
>> I see this in the NEWS for R 3.1.0:
>>
>> type.convert() (and hence by default read.table()) returns a
>> character vector or factor when representing a numeric input as a
>> double would lose accuracy. Similarly for complex inputs.
>>
>> This behavior seems likely to surprise users.
>
> Can you elaborate why that would be surprising? It is consistent with
> the intention of type.convert() to determine the correct type to
> represent the value - it has always used character/factor as a
> fallback where native type doesn't match.

Strictly speaking, I don't think this is true. If it were, it would not 
have been necessary to make the change so that it does now fallback to 
using character/factor. It may, however, have always been the intent.

I don't really think a warning is necessary, but there are some surprises:

 > str(type.convert(format(1/3, digits=17))) # R-3.0.3
  num 0.333

 > str(type.convert(format(1/3, digits=17))) # R-3.1.0
  Factor w/ 1 level "0.33333333333333331": 1

Now you could say that one should never do that, and the change is just 
flushing out a bug that was always there. But the point is that in 
serialization situations there can be some surprises. So, for example, 
RODBC talking to PostgresSQL databases is now returning factors rather 
than numerics for double precision fields, whereas with RPostgresSQL the 
behaviour has not changed.

Paul

It has never issued any
> warning in that case historically, so IMHO it would be rather
> surprising if it did now…
>
> Cheers, Simon
>
>
>> Would it be possible to issue a warning when this occurs?
>>
>> Aside: I’m very happy to see the new ’s’ and ‘f’ browser (debugger)
>> commands!
>>
>> -Greg [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
> ______________________________________________ R-devel at r-project.org
> mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
>



More information about the R-devel mailing list