Learn R Programming

ChemoSpec (version 3.0-1)

splitSpectraGroups: Create New Groups from an Existing Spectra Object

Description

This function takes an existing "Spectra" object and uses your instructions to split the existing spectra$groups into new groups. The new groups are added to the existing "Spectra" object (a list) as new elements. This allows one to use different combinations of factors than were originally encoded in the "Spectra" object. The option also exists to replace the color scheme with one which corresponds to the new factors.

Usage

splitSpectraGroups(spectra, inst = NULL, rep.cols = NULL, ...)

Arguments

spectra
An object of S3 class "Spectra".
inst
A list giving the name of the new element to be created from a set of target strings given in a character vector. See the example for the syntax.
rep.cols
Optional. A vector giving new colors which correspond to the levels of inst. Only possible if inst has only one element, as the possible combinations of levels and colors may get complicated.
...
Additional arguments to be passed downstream. Currently not used.

Value

  • An object of S3 class "Spectra", modified to have additional elements as specified by inst.

Details

The items in the character vector are grepped among the existing spectra$groups entries; when found, they are placed in a new element of spectra. In the example, all spectra$groups entries containing "G" are coded as "G" in a new element called spectra$env, and any entries containing "T" are handled likewise. This amounts to a sort of recoding of factors (the example demonstrates this). Every entry in spectra$groups should be matched by one of the entries in the character vector. If not, you will get entries. Also, if the targets in the character vector are not unique, your results will reflect the order of the levels. Since this is a grep process, you can pass any valid grep string as the target.

If rep.cols is provided, these colors are mapped one for one onto the levels of the the first element of inst. See the example for usage. This provides a different means of changing the sample color encoding than conColScheme.

References

https://github.com/bryanhanson/ChemoSpec

See Also

conColScheme.

Examples

Run this code
data(CuticleIR)
# original factor encoding from when CuticleIR was created:
levels(CuticleIR$groups)
# split those original levels into 2 new ones (re-code them):
new.groups <- list(gen = c("G", "T"), trt = c("C", "E"))
new.CuticleIR <- splitSpectraGroups(CuticleIR, new.groups)
str(new.CuticleIR) # note two new elements, "gen" and "trt"
# split into one new factor and re-color:
new.groups <- list(gen = c("G", "T")) # only one element
new.CuticleIR <- splitSpectraGroups(CuticleIR, new.groups, rep.cols = c("pink", "orange"))
str(new.CuticleIR) # note one new element, "gen" and the colors have changed.

# note that if you want to use a newly created group in
# plotScores and other functions to drive the color scheme, you'll
# have to copy a new group to the groups element:
new.CuticleIR$groups <- new.CuticleIR$gen

Run the code above in your browser using DataLab