unpack: Read and unpack bytes from a binary file connection

Description Usage Arguments Value


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.

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

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.