unpack: Read and unpack bytes from a binary file connection
Description
This function is exported mainly for my own benefit, but maybe
others will find it useful. It is written to bring the python syntax for
binary file reading to R. See the source code of this package for usage
examples. Note a limitation of this approach to binary file reading is that
reading and unpacking are inseparable, which can cause
headaches in some cases.
Usage
unpack(fmt, conn, endianness = "little", n = 1, ...)
Arguments
conn
a connection returned by file
. endianness
string; passed to readBin
. One of
"big"
or "little"
. n
integer; the number of records to read. Also passed to
readBin
. NOTE: this argument is ignored if
fmt = "I"
, due to the way unsigned integers have to be hacked
together. ...
additional arguments to be passed to readBin
. Value
a "scalar" value according to fmt
.