Reading OPUS Binary Files in R
This package implements a driver for FTIR spectroscopy data collected in the OPUS binary format.
This package is a fork from the read_opus_bin_univ from the simplerspec package authored by Philipp Baumann, who deserves all of the credit for this contribution. Here the simplerspec functions are modified so they can read raw streams directly, and to keep the functionality in a lighter package.
You can use the remotes package to install opusreader:
remotes::install_github("pierreroudier/opusreader")
The package includes a sample OPUS spectra for demonstration purposes. Its location can be determined using the function opus_file():
> opus_file()
[1] "/path/to/opusreader/inst/extdata/test_spectra.0"
Two functions are available to actually read the data:
opus_readis the workhorse of the package, and allows to read binary files:
# File name of the OPUS file to read
fn <- opus_file()
# Read OPUS file
s <- opus_read(fn)
# Plot the spectra
plot(s$wavenumbers, s$spec, type = 'l')
- The
opus_read_rawfunction is lower level, and allows to read arawrepresentation of the OPUS file. It is useful if the OPUS file is "streamed" over eg a web service:
# Store OPUS file content as raw binary data
fn <- opus_file()
rw <- readBin(fn, "raw", 1e5)
# Read raw binary data directly
s <- opus_read_raw(rw)
# Plot the spectra
plot(s$wavenumbers, s$spc, type = 'l')