unpack: Read and unpack bytes from a binary file connection

Description Usage Arguments Value

View source: R/struct.R

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

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

Arguments

fmt

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

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.


jmackie4/fitdc documentation built on May 19, 2019, 1:50 p.m.