Extract metadata as a data.frame, data.table or tibble from a list of
chromatograms.
extract_metadata(
chrom_list,
what = chrom_metadata_fields(),
detector = NULL,
format_out = c("data.frame", "data.table", "tibble"),
collapse = FALSE,
expand = FALSE,
by = c("sample", "chromatogram"),
digits = NULL
)A data.frame, tibble, or data.table (according to the value of
format_out), with one row per sample or chromatogram (see by) and the
specified metadata elements as columns, or NA if none of the specified
elements could be found. For a list, the first column, name, identifies
each row: by the sample's name, or with by = "chromatogram" by the
chromatogram's path through the list (e.g. blue.UV).
A list of chromatograms with attached metadata (as returned
by read_chroms with read_metadata = TRUE), or a single chromatogram.
A character vector specifying the metadata elements to
extract. Defaults to every field chromConverter attaches; no format
records all of them, so the elements a format does not provide are
absent from the result. Superseded names (e.g. injection_volume,
software_name, time_start) are accepted and mapped to the names
that replaced them. An element of a nested field (see expand) may be
named too, either by the column it is reported under (SampleLabel) or in
full (acaml_metadata.SampleLabel), to report it without the rest of its
field. A field requested by name that no chromatogram carries produces a
warning.
A character vector of detectors to include (e.g. "UV" or
c("UV", "MS")), matched case-insensitively against each chromatogram's
detector attribute. Defaults to NULL, in which case all chromatograms
are included. Useful for lists containing more than one detector per
sample. It is an error if no chromatogram matches.
Format of object. Either data.frame, data.table or
tibble.
Logical. Whether to collapse a field holding more than one
value (time_range, or the product_mz of an MRM event monitoring several
transitions) into a single comma-separated string. Defaults to FALSE, in
which case such a field is spread across numbered columns
(time_range1, time_range2).
Whether to include the nested metadata fields, whose value is
itself a list or table rather than a single value per chromatogram: the
ms_params and method_params instrument settings, the acaml_metadata
injection record that read_agilent_rslt reads from the .acaml file, or
the whole vendor list that metadata_format = "raw" passes through. Either
TRUE, to include every nested field the chromatograms carry, a character
vector naming the ones to include, or FALSE (the default) to include none.
Each element becomes a column of its own, named for itself (SampleName)
unless that name is already taken, in which case it carries the field it came
from (ms_params.polarity, since polarity is a metadata field in its own
right).
Whether to return one row per sample (the default), that is per
element of chrom_list, or one row per chromatogram. The two differ only
for nested lists, such as the traces read_agilent_d returns for each .D
directory. With by = "sample", each field holds the value that a sample's
chromatograms agree on, ignoring those that leave it empty, and is NA where
they disagree; with the default what, fields that are then empty for every
sample are left out. Fields that belong to each trace, such as detector or
source_file, need by = "chromatogram".
Number of significant digits for the numbers in a field
collapsed into a string (see collapse), or NULL (the default) to keep
them in full. Numeric fields spread across columns are returned as numbers
either way.
path <- system.file("extdata", "benzoxazinoid_standards",
package = "chromConverter")
chroms <- read_chroms(path, format_in = "chemstation_ch", pattern = "dad1A",
parser = "chromconverter", progress_bar = FALSE)
extract_metadata(chroms, what = c("sample_name", "run_datetime", "time_range"))
Run the code above in your browser using DataLab