A quick start to the `spectacles` package

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.align = 'center',
  fig.height = 5,
  fig.width = 5
)
library(spectacles)

Converting data to a SpectraDataFrame

data("australia")
class(australia)
big.head(australia)
spectra(australia) <- sr_no ~ ... ~ 350:2500
summary(australia)

Accessing the different elements of the SpectraDataFrame object

General information about the SpectraDataFrame

nrow returns the number of samples in the object:

nrow(australia)

ncol returns the number of attributes in the data slot of the object, and returns NULL if the object does not have associated data:

ncol(australia)

length returns the number of wavelengths in the object:

length(australia)

dim returns a numeric vector of these three dimensions:

dim(australia)

Subsetting

sub <- australia[1:5,]
summary(sub)

Accessing specific properties of Spectra objects

Specific functions are available to access the various properties of Spectra objects:

ids is returning a vector containing the IDs of the object. It has a as.vector option. When turned to FALSE, the function returns a data.frame instead of a vector. This is particularly useful to retrieve the original column name of the IDs:

# Just printing the first 5
ids(australia)[1:5]

wl is returning the wavelengths of the object in a numeric vector:

# Just printing the first 10
wl(australia)[1:10]

spectra is returning the spectra matrix:

s <- spectra(australia)
class(s)
dim(s)
big.head(s)

wl_units is returning the wavelength units:

wl_units(australia)

features is returning associated data into a data.frame:

df <- features(australia)
class(df)
head(df)

Basic plotting

plot(australia)
plot(australia, col = "royalblue")


Try the spectacles package in your browser

Any scripts or data that you put into this service are public.

spectacles documentation built on Jan. 13, 2021, 8:46 a.m.