[R] Need 64-bit integers on 32-bit platform

Earl F. Glynn efg at stowers-institute.org
Tue May 22 00:38:02 CEST 2007


I'm using the latest R on Windows XP:

> R.version
               _
platform       i386-pc-mingw32
arch           i386
os             mingw32
system         i386, mingw32
status
major          2
minor          5.0
year           2007
month          04
day            23
svn rev        41293
language       R
version.string R version 2.5.0 (2007-04-23)

I understand this:

> .Machine$integer.max
[1] 2147483647

> .Machine$sizeof.longlong
[1] 8

So how can I get a "longlong" (i.e., 64-bit = 8-byte integers) in my 
environment?  Where is there no storage.mode of "longlong" or "int64"?

I'm reading electrophysiology data with a time stamp that's in a 64-bit 
integer (it's a microsecond clock count) but I'm getting negative values 
returned in R:

# Why no warning if this call doesn't return an 8-byte integer?
TimeStamp   <- readBin(connection, integer(), size=8,  1)
[1] -311761023
[1] -311756172

I can get the hex values of these numbers like this:

TimeStamp   <- readBin(connection, raw(),       8)
[1] 81 e7 6a ed 01 00 00 00
[1] 74 fa 6a ed 01 00 00 00

I can see what these number should be by converting to decimal in Excel:
=HEX2DEC("01ed6ae781")
8278173569

=HEX2DEC("01ed6afa74")
8278178420

How can I get these 8-byte integers in R so I don't have to use this ugly 
kludge?

# KLUDGE
TimeStamp   <- readBin(connection, integer(), size=4,  2)

> TimeStamp
[1] -311761023          1

# Convert integers to doubles since a double has larger range for integers 
than 32-bit integers:
>storage.mode(TimeStamp) <- "double"

# This seems to work, but is too ugly:
> TimeStamp[2]*2^32 + (2^32 + TimeStamp[1])
[1] 8278173569

Can anyone suggest a better way?

Thanks for any suggestions.

efg

Earl F. Glynn
Stowers Institute for Medical Research



More information about the R-help mailing list