[R] Test Binary File

Duncan Murdoch murdoch at stats.uwo.ca
Wed Nov 25 14:18:00 CET 2009


On 25/11/2009 7:34 AM, Jason Rupert wrote:
> I've got an error with the way I'm using readBin on a binary file of unknown internal structure.  I know the structure consists of rows and columns, but I'm not sure how many of each.  
>
> So, does anyone know of a valid test set of binary data that I could reference while trying to figure out the technique of using readBin? 
>
> It would be really helpful to try out readBin on a readily available and understood binary file instead of starting with one of dubious internal structure.  
>   
You can write your own.  For example,

f <- tempfile()
writeBin(as.numeric(1:100), f)

The hexView package is very nice for seeing what you've got:

library(hexView)
viewRaw(f)

which will show something like this:

 0  :  00 00 00 00 00 00 f0 3f 00 00 00 00 00 00 00 40  |  .......?.......@
 16  :  00 00 00 00 00 00 08 40 00 00 00 00 00 00 10 40  |  ....... at .......@
 32  :  00 00 00 00 00 00 14 40 00 00 00 00 00 00 18 40  |  ....... at .......@
...

viewRaw(f, human="real")

will show

  0  :  00 00 00 00 00 00 f0 3f 00 00 00 00 00 00 00 40  |    1   2
 16  :  00 00 00 00 00 00 08 40 00 00 00 00 00 00 10 40  |    3   4
 32  :  00 00 00 00 00 00 14 40 00 00 00 00 00 00 18 40  |    5   6
 48  :  00 00 00 00 00 00 1c 40 00 00 00 00 00 00 20 40  |    7   8
...

Duncan Murdoch




More information about the R-help mailing list