Storing, Manipulating and Analysis Spectroscopy and Associated Data

Stores and eases the manipulation of spectra and associated data, with dedicated classes for spatial and soil-related data.


Travis-CI Build Status CRAN_Status_Badge

Scope of the Package

The spectacles package is making it easy (or at least easier!) to handle spectroscopy data. It provides the user with dedicated classes (namely Spectra and SpectraDataFrame), so that most of the useful information about the spectral dataset is available in one R object:

  • the spectral values
  • the wavelengths at which these have been recorded
  • some kind of ID
  • if available, some associated data (typically, some lab measurements)

Installation

spectacles is not on CRAN (yet?), but you can install the latest version using the devtools package:

# Install devtools if you don't have it on your machine
# install.packages('devtools')
devtools::install_github("pierreroudier/spectacles")

Graphical Capabilities

It also provides easy ways to plot a collection of spectra:

  • simple line plots of the individual spectra
  • offset plots of the individual spectra
  • stacked plots of the individual spectra
  • summary plots of a whole collection, or aggregated against a given factor
  • tools to code more advanced visualisations yourself using eg ggplot2 or lattice

It also gives overloads to the most common operators such as $, [, or [[, so that any user familiar with data.frame object would fell right at home.

Processing

The philosophy of the package is really just to make it easier to work with quite complex data. There are a lot of tools already existing in R to do spectral preprocessing (signal, etc.). A few additional tools have been added in spectacles, such as the ASD splice correction.

The idea is for the package to work quite well with the pipe (%>%) operator from the magrittr package, to create chains of pre-processing operators. The function apply_spectra makes it easy to work with any function whose input is either a numeric vector or a matrix:

# Example of splice correction, followed by
# a first derivative, followed by a SNV

my_spectra %>% 
  splice %>% 
  apply_spectra(diff, 1) %>%
  apply_spectra(snv)
  
# Another example using prospectr
my_spectra %>% 
  splice %>% 
  apply_spectra(prospectr::continuumRemoval, wav = wl(.)) %>% 
  plot

Regression and Classification

Again, lots of existing methods available, so spectacles is not re-implementing any of these. There's various ways to use spectacles with the different methods available, but my favoured option is to use it in conjonction with the caret package, which gives a unique API to 160+ models in R:

fit <- train(
  y = s$carbon,
  x = spectra(s),
  method = "pls"
)
spectroSummary(fit)

Hey, that sounds a lot like inspectr?!?

Yes, I once had a package called inspectr on Github, and spectacles is very much the continuation of inspectr. The only reason why inspectr changed name is that someone pushed a package called inspectr on CRAN (despite inspectr being quite visible on Github.... :-/). So, lesson learnt this time!

News

-------------------------- spectacles 0.3-16 (2017-02-27) --------------------------

  • Change of package name
  • Actual CRAN release

-------------------------- inspectr 0.3-15 (2017-02-27) --------------------------

  • Preparation for CRAN release

-------------------------- inspectr 0.3-15 (2014-05-12) --------------------------

  • Corrected bug in continuum_removal()

-------------------------- inspectr 0.3-14 (2013-02-25) --------------------------

  • Added Kennard-Stone algorithm
  • Added splice() method

-------------------------- inspectr 0.3-13 (2013-02-21) --------------------------

  • Now supporting unordered wavelenghts

-------------------------- inspectr 0.3-12 (2012-12-18) --------------------------

  • corrected bug on features() when using exclude_id
  • repalced all occurences of remove_id by exclude_id (for consistency)

-------------------------- inspectr 0.3-11 (2012-04-17) --------------------------

  • new plot_offset() method
  • Default value for as.vector in ids(...) is now TRUE

-------------------------- inspectr 0.3-10 (2012-04-03) --------------------------

  • Fix doco
  • renamed option include_id in features(obj) to remove_id for consistance with features<-
  • Now can use spectra(foo, "rowwise") <- ~ A + B + C (not specifying column for WLs range)

-------------------------- inspectr 0.3-9 (2012-03-28) --------------------------

  • turned plot_summary and plot_stack into S4 methods (that are now properly exported)
  • corrected stuff in [, now more clear for the waevlengths indexing (if index niot in WL range, throws a warning)

-------------------------- inspectr 0.3-8 (2012-03-27) --------------------------

  • removed spectra_long() and spectra_wide(), replace by a mode=... option in spectra<-
  • now spectra<- and features<- should pass R CMD check without any NOTE

-------------------------- inspectr 0.3-7 (2012-03-23) --------------------------

  • Corrected CITATION, DESCRIPTION and NAMESPACE
  • added "upper=" option in continuum_removal
  • plot made faster by removing unecessary stuff in fill_spectra when there's no gaps
  • added plot_stack.Spectra (still in dev though)

-------------------------- inspectr 0.3-6 (2012-03-21) --------------------------

  • various small bugfixes
  • new default plot() method using base graphics and matplot - much faster
  • as a consequence, lattice is not required anymore
  • added a default colour scheme

-------------------------- inspectr 0.3-5 (2012-03-19) --------------------------

  • more bugfixes
  • examples in docs
  • doc should be 95pct complete now

-------------------------- inspectr 0.3-4 (2012-03-19) --------------------------

  • added "australia" data
  • big clean NAMESPACE
  • various bugfixes

-------------------------- inspectr 0.3-3 (2012-03-16) --------------------------

  • baseline renamed base_line to remove confusion
  • bugfix for base_line()

-------------------------- inspectr 0.3-2 (2012-03-16) --------------------------

  • fixed important bug on plot() method
  • fixed silly bug on subset.SpectraDataFrame
  • fixed big on cut.Spectra

-------------------------- inspectr 0.3-1 (2012-03-15) --------------------------

  • included new dim() method
  • corrected important bug: now init possible using SDF (not only S) using SpectraDataFrame()

-------------------------- inspectr 0.3-0 (2012-03-15) --------------------------

  • ids can be returned as a data.frame or a vector (using as.vector option of ids())
  • ids can be collated to the features in the features() method
  • New rbind.Spectra*() method
  • add() method removed
  • new cut() method to select or remove WLs
  • new apply_spectra() method
  • various improvements on the plotting routine
  • Added plot_summary() method
  • Bugfixes on aggregate_spectra()
  • spectra() now returns wavelengths specified by the @wl slot
  • Added proper split-apply-combine strategy for aggregate_spectra()
  • features()<- method introduced
  • first prototype of a soil data support
  • [ method improved to support negative indices
  • [i, j, k, ... method introduced for SpectraDataFrame. i for rows, j for data cols, k for spectra
  • Fixed and improved as.data.frame() methods
  • improved melt_spectra() method. Now accepts a attr=... option for SDF.
  • resolution method renamed res to avoid conflict with ggplot2
  • removed unseparate() method as rbind() is doing the exact same thing now
  • separate() now available for Spectra objects
  • bugfixes on mutate()
  • introduced distinct spectra_wide<- and spectra_long<- initialising functions
  • [[ and $ can now be used to promote a Spectra to a SpectraDataFrame object

-------------------------- inspectr 0.2-0 (2011-11-10) --------------------------

  • Switch the get_data()/data() methods to features() (as data() is protected)
  • Introduced sp bindings - and thus new spatial aware classes
  • Changed classes definitions location in a single file

-------------------------- inspectr 0.1-7 (2011-06-20) --------------------------

  • Changed package name and swithed to R-forge

-------------------------- specstore 0.1-6 (2011-06-07) --------------------------

  • bug fix of aggregate_spectra (bug #1, "evaluation nested too deeply" error)

-------------------------- specstore 0.1-5 (2011-06-01) --------------------------

  • bug fix when initializing a Spectra object without any id field.

-------------------------- specstore 0.1-4 (2011-05-31) --------------------------

  • [i, j, .. method now accepts j values to subset the wavelengths

-------------------------- specstore 0.1-3 (2011-05-26) --------------------------

  • split() now works for any class inheriting from Spectra
  • New spectra<-.Spectra method, allowing to change the spectra of a Spectra* object by passing a matrix with the same number of rows.

-------------------------- specstore 0.1-2 (2011-05-25) --------------------------

  • Method get_units() is now called units()
  • Method get_resolution() is now called resolution()
  • Method get_data() is now called data()
  • New units<- method (changes the unit in which the wavelengths are expressed)
  • New split.SpectraDataFrame method, see ?split
  • mutate() is now implemented as one only method (not anymore duplicated for each Class), and is now working properly with attributes. You can even muate the spcetra and the attributes of an object in one command.

-------------------------- specstore 0.1-1 (2011-05-24) --------------------------

  • proper package structure and documentation
  • first semi-public release

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("spectacles")

0.5-0 by Pierre Roudier, a year ago


https://github.com/pierreroudier/spectacles/


Report a bug at https://github.com/pierreroudier/spectacles/issues


Browse source code at https://github.com/cran/spectacles


Authors: Pierre Roudier [aut, cre] , Max Kuhn [ctb] , Kristian Hovde Liland [ctb] , Bjorn-Helge Mevik [ctb] , Hadley Wickham [ctb] , Raphael Viscarra Rossel [dtc]


Documentation:   PDF Manual  


GPL-3 license


Imports ggplot2, methods, plyr, reshape2, stringr, baseline, signal, epiR

Suggests caret, pls, RColorBrewer


See at CRAN