[R] Reading binary files

Nortisiv simon.klapper at uni-duesseldorf.de
Tue Jun 12 09:51:15 CEST 2012


Hey guys,

I am currently trying to read in a binary file using this helpful manual:
http://www.ats.ucla.edu/stat/r/faq/read_binary.htm Reading binary files 

I also have the detailed format description from the developer. But somehow
the reading of the file does still not work properly. The first entry in the
file is the following, according to the manufacturer:
"String containing 4 one-byte characters."
The content should be "ABF", as I was able to confirm with an external
Hex-Editor, so in general everything is correct.
But when I try to read out the first entry in R, I can see that R reads the
first 12 bytes, although I tell it to read only 4 bytes, using the "Size"
option (as I found out using the Hex-Editor):

> to.read = file("test.DAT", "rb")
> readBin(to.read, character(), size=4, endian = "little")
[1] "ABF ff¦?\005"

Why does R do this? Changing the size parameter seems to have no efect on
the output "ABF ff¦?\005". Any idea whats going wrong? 

--
View this message in context: http://r.789695.n4.nabble.com/Reading-binary-files-tp4633078.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list