To create a new hyperSpec
object, you can use one of the following functions:
new()
(i.e., new("hyperSpec", ...)
);
hyperSpec()
.
hyperSpec(
spc = NULL,
data = NULL,
wavelength = NULL,
labels = NULL,
gc = hy_get_option("gc"),
log = "ignored"
)
# S4 method for hyperSpec
initialize(
.Object,
spc = NULL,
data = NULL,
wavelength = NULL,
labels = NULL,
gc = hy_get_option("gc"),
log = "ignored"
)
(matrix
or convertible to matrix
)
A spectra matrix with spectra in rows and wavelength intensities in
columns.
The spc
does not need to be an R matrix
, but it must be an object
convertible to a matrix via I(as.matrix(spc))
.
(data.frame
)
A data.frame
with extra (non-spectroscopic) data in columns.
The data frame may also contain a special column spc
with a matrix
of spectroscopic data.
(Such a single column that contains a matrix can be created with
data.frame(spc = I(as.matrix(spc)))
.
However, it is usually more convenient to provide the spectra
via the spc
argument.)
(numeric vector)
The wavelengths corresponding to the columns of spc
.
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.
A named list
:
list's element names should contain one or more names of data
columns as well as the special name .wavelength
for wavelength
s.
list's element values should contain the labels for the indicated
names, usually in the form of character strings or
plotmath expressions.
(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.
(logical)
Use garbage collection.
If the option gc
is set to TRUE
, the initialization will have
frequent calls to base::gc()
, which can help avoid swapping or
running out of memory.
The default value of gc
can be set via hy_set_options()
.
This parameter is currently ignored. It is present due to backward compatibility.
A new hyperSpec
object.
A hyperSpec
object is an S4 object, so its initialization is performed
by calling new("hyperSpec", ...)
. The function hyperSpec()
is provided
for convenience.
methods::new()
for more information on creating and initializing S4 objects.
grDevices::plotmath()
for expressions used for math annotations as in the label
slot.
hy_set_options()
for setting hyperSpec
options.
new("hyperSpec")
#> hyperSpec object
#> 0 spectra
#> 1 data columns
#> 0 data points / spectrum
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
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 take precedence 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)
plot_c(h, spc ~ pos)
#> Warning: Intensity at first wavelengh only is used.