Thespectacles package is making it easy (or at leasteasier!) to handle spectroscopy data. It provides the user withdedicated classes (namelySpectra andSpectraDataFrame), so that most of the useful informationabout the spectral dataset is available in one R object:
The stable version ofspectacles is on CRAN(:tada:):
install.packages('spectacles')You can also install the development version using thedevtools package:
# Install devtools if you don't have it on your machine# install.packages('devtools')devtools::install_github("pierreroudier/spectacles")It also provides easy ways to plot a collection of spectra:
ggplot2 orlatticeIt also gives overloads to the most common operators such as$,[, or[[, so that any userfamiliar withdata.frame object would fell right athome.
The philosophy of the package is really just to make it easier towork with quite complex data. There are a lot of tools already existingin R to do spectral preprocessing (signal, etc.). A fewadditional tools have been added inspectacles, such as theASD splice correction.
The idea is for the package to work quite well with the pipe(%>%) operator from themagrittr package,to create chains of pre-processing operators. The functionapply_spectra makes it easy to work with any function whoseinput is either anumeric vector or amatrix:
# Example of splice correction, followed by# a first derivative, followed by a SNVmy_spectra %>% splice %>% apply_spectra(diff, 1) %>% apply_spectra(snv) # Another example using prospectrmy_spectra %>% splice %>% apply_spectra(prospectr::continuumRemoval, wav = wl(.)) %>% plotAgain, lots of existing methods available, sospectaclesis not re-implementing any of these. There’s various ways to usespectacles with the different methods available, but myfavoured option is to use it in conjonction with thecaretpackage, which gives a unique API to 160+ models in R:
fit <- train( y = s$carbon, x = spectra(s), method = "pls")spectroSummary(fit)inspectr?!?Yes, I once had a package calledinspectr on Github, andspectacles is very much the continuation ofinspectr. The only reason whyinspectr changedname is that someone pushed a package calledinspectr onCRAN (despiteinspectr being quite visible on Github….:-/). So, lesson learnt this time!