Attaches the columns of a table to the chromatograms of a chrom_list as
metadata fields, matching each row to a sample by name. The new fields can
then be used by subset.chrom_list and requested from extract_metadata.
Where an element holds several chromatograms, such as the traces
read_agilent_d returns for each .D directory, every one of them gets the
sample's values.
Arguments
- chrom_list
A
chrom_listobject.- metadata
A
data.frame,tibbleordata.tablewith one row per sample.- by
The column of
metadataholding the sample names, matched tonames(chrom_list). Defaults toname, the column extract_metadata identifies samples by.- overwrite
Whether a column may replace a field that chromConverter reads from the file, such as
sample_name. Defaults toFALSE, in which case such a column is an error.
Value
chrom_list with the columns of metadata attached to its
chromatograms, and their names recorded in an added_metadata attribute,
from which chromatographR's get_peaktable fills its sample_meta. A
sample without a row in metadata is left unchanged, with a warning.
Examples
path <- system.file("extdata/ladder.txt", package = "chromConverter")
chrom <- read_chroms(path, format_in = "shimadzu_ascii",
find_files = FALSE, progress_bar = FALSE)
# three copies stand in for the samples of a sequence
chroms <- c(chrom, chrom, chrom)
names(chroms) <- c("s1", "s2", "s3")
meta <- data.frame(name = c("s1", "s2", "s3"),
treatment = c("control", "drought", "drought"))
chroms <- add_metadata(chroms, meta)
extract_metadata(chroms, what = "treatment")
#> name treatment
#> 1 s1 control
#> 2 s2 drought
#> 3 s3 drought
names(subset(chroms, treatment == "drought"))
#> [1] "s2" "s3"
