From avraham.adler at gmail.com  Tue Apr 14 08:24:19 2015
From: avraham.adler at gmail.com (Avraham Adler)
Date: Tue, 14 Apr 2015 02:24:19 -0400
Subject: [Rd] behavior of as.integer("5000000000")
In-Reply-To: <552CA376.7000601@fredhutch.org>
References: <552CA376.7000601@fredhutch.org>
Message-ID: <CAL6gwn+a-XKgv3sBSoHYmF=z0x8RxqyghvOuKAo+re0dactkDw@mail.gmail.com>

On Tue, Apr 14, 2015 at 1:19 AM, Herv? Pag?s <hpages at fredhutch.org> wrote:
> Hi,
>
>   > as.integer("5000000000")
>   [1] 2147483647
>   Warning message:
>   inaccurate integer conversion in coercion
>
>   > as.integer("-5000000000")
>   [1] NA
>   Warning message:
>   inaccurate integer conversion in coercion
>
> Is this a bug or a feature? The man page suggests it's the latter:


Hello, Herv?

Per help("as.integer"): "Note that current implementations of R use
32-bit integers for integer vectors, so the range of representable
integers is restricted to about +/-2*10^9: doubles can hold much
larger integers."

5000000000 ~ 2^32.2 > 2^32 > 2*10^9

Avi


>
>   ?as.integer? attempts to coerce its argument to be of integer
>   type.  The answer will be ?NA? unless the coercion succeeds.
>
> even though someone could always argue that coercion of "5000000000"
> succeeded (for some definition of "succeed").
>
> Also is there any reason why the warning message is different than
> with:
>
>   > as.integer(-5000000000)
>   [1] NA
>   Warning message:
>   NAs introduced by coercion
>
> In the case of as.integer("-5000000000"), it's not really that the
> conversion was "inaccurate", it's a little bit worse than that. And
> knowing that NAs where introduced by coercion is important.
>
> Thanks,
> H.
>
> --
> Herv? Pag?s
>
> Program in Computational Biology
> Division of Public Health Sciences
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N, M1-B514
> P.O. Box 19024
> Seattle, WA 98109-1024
>
> E-mail: hpages at fredhutch.org
> Phone:  (206) 667-5791
> Fax:    (206) 667-1319
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] behavior of as.integer("5000000000")
Avraham Adler