[R] reading short int and float from binary connection

Angel Lopez angel_lul at hotmail.com
Wed Mar 17 13:31:46 CET 2004


Thanks for the advise.
I think I've found the solution, the problem was that the file had been 
written from a C program using a structure containing floats and int, if 
I rewrite the C code not using a structure but independent floats and 
ints the data then is read smoothly into R. I still can't figure out why 
a structure is different or how should I have read it into R but it is 
probably more a C than an R question .
Thanks,
Angel

Uwe Ligges wrote:

> Angel Lopez wrote:
>
>> Hi,
>> I have a binary file with mixture of short integers (2 bytes) and 
>> floats (4 bytes).
>> To get the data into R I use readBin reading each value one at a time 
>> (n=1) but it is giving me headaches, two questions:
>> -In the "what" option is there any difference between "integer" and 
>> "int"?
>> -To read the short int I use what="int" and size=2 and to read the 
>> floats I use what="double" and size=4, the strange thing is that 
>> sometimes it works but other times it reads wrong values.
>> Any clues where my mistake might be?
>> Thanks
>> Angel
>
>
>
> Are the inetgers signed or not? You might want to set signed = FALSE 
> for unsigned integers.
> Are you sure you are reading each time from the beginning of the 
> connection?
> Are you really sure about the file format specifications?
>
> Difficult to track down without your code, the file format's 
> specification, and an example file..
>
> Uwe Ligges
>
> .
>




More information about the R-help mailing list