Description Arguments Examples
The Spectrum
class is a simple list of elements. There are two
classes of elements. Mandatory elements such as the MS level of
the spectrum (msLevel
), its retention time (rtime
), ... that
must be of a pre-defined class (see the Spectrum_elements
vector
for their names and classes). Optional elements with arbitrary
names and classes can also be added.
If, as some point, some elements were to become mandatory, their
names and classes would simply need to be added to the
Spectrum_elements
vector.
Object are created with the Spetrum(...)
constructor. Spectrum()
generates a instance with empty valid
values.
... |
Mandatory spectrum elements or list thereof. See
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | ## An empty spectrum
sp <- Spectrum()
sp
## Mandatory elements
Spectrum_elements
## Updating mandatory elements
sp$msLevel
class(sp$msLevel)
sp$msLevel <- 2L ## works
sp$msLevel
try(sp$msLevel <- "not an integer")
sp$msLevel
pa <- PeakAnnotation(peaks = list(c(345.3, 345.32, 345.35, 345.39, 345.4),
657.01,
1231.182),
annotations = list("a5", "z3", "y7"))
sp$peakAnnotation
sp$peakAnnotation <- pa
sp$peakAnnotation
## Adding arbitrary elements
sp$foo <- "bar"
sp
## All current elements (mandatory and optional) and their
## respective classes
sapply(sp, class)
## Setting intensity and m/z values. These must be set together,
## as these two elements must be of the same length.
mz <- as.numeric(sample(1000, 10))
i <- as.numeric(sample(1e3:1e5, 10))
sp[c("intensity", "mz")] <- list(i, mz)
plot(sp$mz, sp$intensity, type = "h")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.