Skip to content
Back to formatted view

Raw Message

Message-ID: <4B0D2E88.9020202@stats.uwo.ca>
Date: 2009-11-25T13:18:00Z
From: Duncan Murdoch
Subject: Test Binary File
In-Reply-To: <982584.590.qm@web56006.mail.re3.yahoo.com>

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