pm_load_spectra takes a column with file names for files containing mid infrared spectra from a data frame, imports the spectra into a list column spectra and adds them to the data frame which then becomes an ir::ir_new_ir[ir] object.

pm_load_spectra(
  x,
  directory = ".",
  .col_files = "mirs_file",
  .col_sample_id = "id_sample"
)

Arguments

x

A data frame.

directory

A character value specifying the directory where the files accompanying the 'pmird' database are stored.

.col_files

The name of the column of x with file names for the files storing mid infrared spectra.

.col_sample_id

The name of the column of x with names for the samples for which to load spectra. This column is used as column sample_id when constructing the ir object.

Value

x as an object of class ir and with a new column spectra.

Details

Currently, the following file formats are supported for files storing mid infrared spectra:

  1. csv files

  2. Thermo Galactic's .spc files

Examples

if (FALSE) { # connect to database con <- RMariaDB::dbConnect( # ---todo: change this drv = RMariaDB::MariaDB(), dbname = "pmird", default.file = "~/my.cnf" ) # extract data x <- pm_get_dm(con, learn_keys = TRUE) %>% dm::dm_zoom_to(data) %>% dplyr::filter(id_measurement < 1000 & ! is.na(mirs_file)) %>% dm::pull_tbl() %>% as.data.frame() # close connection RMariaDB::dbDisconnect(con) # get spectra x <- pm_load_spectra(x, directory = "..", .col_files = "mirs_file", .col_sample_id = "id_measurement") class(x) }