Extract metadata as a data.frame, data.table or tibble from a list of
chromatograms.
Arguments
- chrom_list
A list of chromatograms with attached metadata (as returned by
read_chromswithread_metadata = TRUE), or a single chromatogram.- what
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 (seeexpand) 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.- detector
A character vector of detectors to include (e.g.
"UV"orc("UV", "MS")), matched case-insensitively against each chromatogram'sdetectorattribute. Defaults toNULL, 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_out
Format of object. Either
data.frame,data.tableortibble.- collapse
Logical. Whether to collapse a field holding more than one value (
time_range, or theproduct_mzof an MRM event monitoring several transitions) into a single comma-separated string. Defaults toFALSE, in which case such a field is spread across numbered columns (time_range1,time_range2).- expand
Whether to include the nested metadata fields, whose value is itself a list or table rather than a single value per chromatogram: the
ms_paramsandmethod_paramsinstrument settings, theacaml_metadatainjection record thatread_agilent_rsltreads from the.acamlfile, or the whole vendor list thatmetadata_format = "raw"passes through. EitherTRUE, to include every nested field the chromatograms carry, a character vector naming the ones to include, orFALSE(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, sincepolarityis a metadata field in its own right).- by
Whether to return one row per
sample(the default), that is per element ofchrom_list, or one row perchromatogram. The two differ only for nested lists, such as the traces read_agilent_d returns for each.Ddirectory. Withby = "sample", each field holds the value that a sample's chromatograms agree on, ignoring those that leave it empty, and isNAwhere they disagree; with the defaultwhat, fields that are then empty for every sample are left out. Fields that belong to each trace, such asdetectororsource_file, needby = "chromatogram".- digits
Number of significant digits for the numbers in a field collapsed into a string (see
collapse), orNULL(the default) to keep them in full. Numeric fields spread across columns are returned as numbers either way.
Value
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).
Examples
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"))
#> name sample_name run_datetime time_range1 time_range2
#> 1 MEOH MEOH 2023-06-15 16:46:23 -0.03716667 59.95617
#> 2 BENZOS_1000PPM benzos_1000ppm 2023-06-20 19:29:41 -0.04333333 59.95667
#> 3 BENZOS_500PPM benzos_500ppm 2023-06-21 15:23:43 -0.04233333 59.95767
#> 4 BENZOS_250PPM benzos_250ppm 2023-06-21 16:46:40 -0.03783333 59.95550
#> 5 BENZOS_125PPM benzos_125ppm 2023-06-21 18:02:48 -0.04166667 59.95833
#> 6 BENZOS_62,5PPM benzos_62,5ppm 2023-06-21 19:19:00 -0.04016667 59.95983
#> 7 BENZOS_31,25PPM benzos_31,25ppm 2023-06-21 20:35:12 -0.03716667 59.95617
#> 8 BENZOS_16PPM benzos_16ppm 2023-06-21 21:51:21 -0.03933333 59.96067
#> 9 BENZOS_8PPM benzos_8ppm 2023-06-21 23:07:28 -0.04050000 59.95950
#> 10 BENZOS_4PPM benzos_4ppm 2023-06-22 00:23:39 -0.03933333 59.96067
