Like other S4 objects, a hyperSpec object can be created by new(). The hyperSpec object is then initialized using the given parameters. As an alias, function new_hyperSpec() can be used.

# S4 method for hyperSpec
initialize(.Object, spc = NULL, data = NULL, wavelength = NULL, labels = NULL)

new_hyperSpec(spc = NULL, data = NULL, wavelength = NULL, labels = NULL)

Arguments

.Object

the new hyperSpec object.

spc

the spectra matrix. spc does not need to be a matrix, it is converted explicitly by I(as.matrix(spc)).

data

data.frame, possibly with the spectra in data$spc, and further variates in more columns. A matrix can be entered as one column of a data frame by: data.frame(spc = I(as.matrix(spc))).

However, it will usually be more convenient if the spectra are given in spc.

wavelength

The wavelengths corresponding to the columns of data. If no wavelengths are given, an appropriate vector is derived from the column names of data$spc. If this is not possible, 1:ncol(data$spc) is used instead.

labels

A list containing the labels for the columns of the data slot of the hyperSpec object and for the wavelength (in label$.wavelength). The labels should be given in a form ready for the text-drawing functions (see grDevices::plotmath()).

If label is not given, a list containing NULL for each of the columns of data and wavelength is used.

Details

If option gc is TRUE (see hy_set_options()), the initialization will have frequent calls to gc(), which can help to avoid swapping or running out of memory.

See also

Author

C.Beleites

Examples


new("hyperSpec")
#> hyperSpec object
#>    0 spectra
#>    1 data columns
#>    0 data points / spectrum
new_hyperSpec()
#> hyperSpec object
#>    0 spectra
#>    1 data columns
#>    0 data points / spectrum

spc <- matrix(rnorm(12), ncol = 4)
new("hyperSpec", spc = spc)
#> hyperSpec object
#>    3 spectra
#>    1 data columns
#>    4 data points / spectrum
new_hyperSpec(spc = spc)
#> hyperSpec object
#>    3 spectra
#>    1 data columns
#>    4 data points / spectrum

new("hyperSpec",
  data = data.frame(x = letters[1:3]),
  spc = spc
)
#> hyperSpec object
#>    3 spectra
#>    2 data columns
#>    4 data points / spectrum

colnames(spc) <- 600:603
new("hyperSpec", spc = spc) # wavelength taken from colnames (spc)
#> hyperSpec object
#>    3 spectra
#>    1 data columns
#>    4 data points / spectrum

# given wavelengths precede over colnames of spc
new("hyperSpec", spc = spc, wavelength = 700:703)
#> hyperSpec object
#>    3 spectra
#>    1 data columns
#>    4 data points / spectrum

# specifying labels
h <- new("hyperSpec",
  spc = spc, data = data.frame(pos = 1:3),
  label = list(
    spc = "I / a.u.",
    .wavelength = expression(tilde(nu) / cm^-1),
    pos = expression("/"(x, mu * m))
  )
)

plot(h)

plotc(h, spc ~ pos)
#> Warning: Intensity at first wavelengh only is used.