Skip to content
Import spectral data and related metadata in R
R TeX
Branch: master
Clone or download
Pull request Compare This branch is even with ropensci:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
R
inst
man
tests
vignettes
.Rbuildignore
.gitignore
.travis.yml
DESCRIPTION
LICENSE.md
NAMESPACE
NEWS.md
README.md
_pkgdown.yml
appveyor.yml
codecov.yml
codemeta.json
cran-comments.md
lightR.Rproj

README.md

lightr: import spectral data in R

Project Status: Active – The project has reached a stable, usable state and is being actively developed. Travis build status AppVeyor build status Coverage status DOI Under review at rOpenSci status

There is no standard file format for spectrometry data and different scientific instrumentation companies use wildly different formats to store spectral data. Vendor proprietary softwares sometimes have an option but convert those formats instead human readable files such as csv but in the process, most metadata are lost. However, those metadata are critical to ensure reproducibility (White et al, 2015).

This package aims at offering a unified user-friendly interface for users to read UV-VIS reflectance/transmittance/absorbance spectra files from various formats in a single line of code.

Additionally, it provides for the first time a fully free and open source solution to read proprietary spectra file formats on all systems.

🔧 Install

This package is not yet published on CRAN and must be installed via GitHub:

# install.packages("remotes")
remotes::install_github("ropensci/lightr")

If you're using Windows and you want to use multiple cores for file import, you can install the development version from the future branch:

# install.package("remotes")
remotes::install_github("ropensci/lightr@future")

💻 Usage

A thorough documentation is available with the package, using R usual syntax ?function or help(function). However, users will probably mainly use two functions:

# Get a data.frame containing all useful metadata from spectra in a folder
lr_get_metadata(where = system.file("testdata/procspec_files", 
                                    package = "lightr"), 
                ext = "ProcSpec")

and

# Get a single dataframe where the first column contains the wavelengths and 
# the next columns contain a spectra each (pavo's rspec class)
lr_get_spec(where = system.file("testdata/procspec_files", package = "lightr"),
            ext = "ProcSpec")

lr_get_spec() returns a dataframe that is compatible with pavo custom S3 class (rspec) and can be used for further analyses using colour vision models.

All supported file formats can also be parsed using the lr_parse_$extension() function where $extension is the lowercase extension of your file. This family of functions return a list where the first element is the data dataframe and the second element is a vector with relevant metadata.

Only exceptions are .txt and .Transmission files because those extensions are too generic. Users will need to figure out which parser is appropriate in this case. lr_get_metadata() and lr_get_spec() automatically try generic parsers in this case.

Alternatively, you may simply want to convert your spectra in a readable standard format and carry on with your analysis with another software.

In this case, you can run:

# Convert every single ProcSpec file to a csv file with the same name and 
# location
lr_convert_tocsv(where = system.file("testdata/procspec_files", 
                                      package = "lightr"),
                 ext = "ProcSpec")

✔ Supported file formats

This package is still under development but currently supports:

OceanOptics

Extension Parser
jdx lr_parse_jdx()
ProcSpec lr_parse_procspec()
jaz lr_parse_jaz()
jazirrad lr_parse_jazirrad()
Transmission lr_parse_jaz()
txt lr_parse_jaz()

Avantes

Extension Parser
ABS lr_parse_abs()
ROH lr_parse_roh()
TRM lr_parse_trm()
trt lr_parse_trt()
ttt lr_parse_ttt()
txt lr_parse_generic()

CRAIC

Extension Parser
txt lr_parse_generic()

Others

Extension Parser
csv lr_parse_generic(sep = ",")
dpt lr_parse_generic(sep = ",")

Others

As a fallback, you should always try lr_parse_generic() which offers a flexible and general algorithm that manages to extract data from most files.

If you can't find the best parser for your specific file or if you believe you are using an unsupported format, please open an issue or send me an email.

🌐 Similar projects

  • lightr itself contains some code that has been initially forked from pavo, namely the lr_get_spec() function. The code has since then been refactored and optimised for speed. pavo differs from lightr in its focus and core functionalities. The main strength of pavo is the comprehensive and user-friendly set of functions to analyse spectral data using colour vision models, while lightr focuses on the data import step.
  • photobiologyInOut also provides functions to import spectral data. The goal of the author is to provide a complete pipeline of spectral data import and analysis using a set of tightly integrated R packages. This however makes it more difficult to use a different tool for a given step of the process. On the contrary, lightr aims at proposing a light package with limited dependencies that focuses on the data import step of the process and let the user pick their favourite tool for the analysis step (pavo, colourvision, Avicol, etc.).
  • spectrolab

To our knowledge, lightr is the only gratis tool to import some complex file formats such as Avantes binary files or OceanOptics .ProcSpec. Because of its user-friendly high-levels functions and low dependency philosophy, lightr may also hopefully prove useful for people working with other languages than R.

ropensci_footer

You can’t perform that action at this time.