Adds an new entry to an existing colleciton object.

add_spectrum(x, ...)

# S3 method for collection
add_spectrum(
  x,
  values,
  left,
  right,
  id = deparse(substitute(values)),
  label = NA,
  ...
)

Arguments

x

A collection object.

...

further arguments passed to or from other methods(not currenctly used).

values

A vector of intensity values.

left

A dbl, left limit of the spectra, corresponds to the first element of values

right

A dbl, right limit of the spectra, corresponds to the last element of values

id

A unique identifier for the sample.

label

A label for the sample.

Value

An updated version of x.

Details

It is assumed that the binning is uniform and correspond to point measurments.

Be careful with the values of leftand right! THis is important for example for NMR data which are usually given with a reversed y-axis.

labels should be used to provide meanigful labels to the samples, e.g. 'treated' and 'control'.

It is recommended to populate a collection using purrr::walk on a list of files (see example).

Examples

#################################################################### # A simple example: adding a spectra from a vector of values: library(tidySpectR) # Genearating some values values = runif(50) left = 0 right = 49 # Collection is empty on creation coll = collection() # Adding the data coll %>% add_spectrum(values, left, right, id = "basic_example", label = "test")
#> Spectra collection containing 1 entries. #> Number of bins: 50 #> Limits: -0.5 49.5 #> Labels: test #> #> Processing:
#################################################################### if (FALSE) { # Real life example: parsing data form file and adding them to a # collection on the fly library(purrr) # Generate a list of file paths for a folder containing spectra data files folder_path <- "path/to/data/folder" files <- file.path(folder_path, list.files(folder_path)) # Create a collection and add the spectra coll <- collection() purrr::walk(files, function(x){ # Parse your files to extract values, limits and ids # ... coll <<- coll %>% add_spectrum(values, left, right, id) }) }