Sorry for the simple question, but I am trying to read an "unsigned long long" using the R readBin() function. Can someone point me in the right direction, or am I better off using C for such things? The file that I am reading will have been produced on the same machine that is doing the reading. Thanks, Sean
Simon Urbanek
2008-May-30 17:48 UTC
[Rd] Reading an "unsigned long long" using R readBin()
On May 29, 2008, at 2:41 PM, Sean Davis wrote:> Sorry for the simple question, but I am trying to read an "unsigned > long long" using the R readBin() function. Can someone point me in > the right direction, or am I better off using C for such things? > The file that I am reading will have been produced on the same > machine that is doing the reading. >R has no data type that can hold 64-bit integers (long long), so there is no (lossless) way to read such a field in R. If you know the endianness of the machine you can read two integers and combine the result as a float to get an approximate value. Otherwise C is your friend (and easy to call from R) for 64-bit calculations, bitwise operations and other tricks that are hard to do in R. Cheers, Simon
Prof Brian Ripley
2008-May-30 17:55 UTC
[Rd] Reading an "unsigned long long" using R readBin()
Well, R has no unsigned quantities, so ultimately you can't actually do this. But using what="int" and an appropriate 'size' (likely to be 8) shold read the numbers, wrapping around very large ones to be negative. (The usual trick of storing integers in numeric will lose accuracy, but might be better than nothing.) On Thu, 29 May 2008, Sean Davis wrote:> Sorry for the simple question, but I am trying to read an "unsigned > long long" using the R readBin() function. Can someone point me in > the right direction, or am I better off using C for such things? The > file that I am reading will have been produced on the same machine > that is doing the reading. > > Thanks, > Sean > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595