unpack: Read and unpack bytes from a binary file connection

Description Usage Arguments Value

View source: R/struct.R


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.


unpack(fmt, conn, endianness = "little", n = 1, ...)



a format character according to the python struct library docs. The following are currently supported: "xbBhHiIs".


a connection returned by file.


string; passed to readBin. One of "big" or "little".


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.


a "scalar" value according to fmt.

fitdc documentation built on May 29, 2017, 7:08 p.m.

Search within the fitdc package
Search all R packages, documentation and source code