
Merging, combining and splitting Chromatograms
Source:R/Chromatograms.R
concatenateChromatograms.RdVarious functions are available to combine or split data from one or more
Chromatograms objects. These are:
c()andconcatenateChromatograms(): combines severalChromatogramsobjects into a single object. The resultingChromatogramscontains all data from all individualChromatograms, i.e. the union of all their chromatograms variables. Concatenation will fail if the processing queue of any of theChromatogramsobjects is not empty or if different backends are used for theChromatogramsobjects. In such cases it is suggested to first change the backends of allChromatogramsto the same type of backend (using thesetBackend()function) and to eventually (if needed) apply the processing queue using theapplyProcessing()function.split(): splits theChromatogramsobject based on a provided grouping factor returning alistofChromatogramsobjects.
Examples
## Create two Chromatograms objects
cdata1 <- data.frame(
msLevel = c(1L, 1L),
mz = c(112.2, 123.3),
dataOrigin = c("file1", "file1")
)
pdata1 <- list(
data.frame(rtime = c(1.0, 2.0, 3.0), intensity = c(100, 200, 150)),
data.frame(rtime = c(1.0, 2.0, 3.0), intensity = c(80, 120, 90))
)
chr1 <- Chromatograms(
ChromBackendMemory(),
chromData = cdata1,
peaksData = pdata1
)
cdata2 <- data.frame(
msLevel = c(2L, 2L),
mz = c(134.4, 145.5),
dataOrigin = c("file2", "file2")
)
pdata2 <- list(
data.frame(rtime = c(4.0, 5.0, 6.0), intensity = c(300, 400, 350)),
data.frame(rtime = c(4.0, 5.0, 6.0), intensity = c(200, 250, 180))
)
chr2 <- Chromatograms(
ChromBackendMemory(),
chromData = cdata2,
peaksData = pdata2
)
## Combine using c()
chr_combined <- c(chr1, chr2)
chr_combined
#> Chromatographic data (Chromatograms) with 4 chromatograms in a ChromBackendMemory backend:
#> chromIndex msLevel mz
#> 1 NA 1 112.2
#> 2 NA 1 123.3
#> 3 NA 2 134.4
#> 4 NA 2 145.5
#> ... 4 more chromatogram variables/columns
#> ... 2 peaksData variables
#> Processing:
#> Merged 2 Chromatograms into one [Tue Aug 18 12:08:12 2026]
## Combine using concatenateChromatograms
chr_combined2 <- concatenateChromatograms(chr1, chr2)
## Combine a list of Chromatograms
chr_list <- list(chr1, chr2)
chr_combined3 <- concatenateChromatograms(chr_list)
## Split by msLevel
chr_split <- split(chr_combined, f = chr_combined$msLevel)
chr_split
#> $`1`
#> Chromatographic data (Chromatograms) with 2 chromatograms in a ChromBackendMemory backend:
#> chromIndex msLevel mz
#> 1 NA 1 112.2
#> 2 NA 1 123.3
#> ... 2 more chromatogram variables/columns
#> ... 2 peaksData variables
#> Processing:
#> Merged 2 Chromatograms into one [Tue Aug 18 12:08:12 2026]
#>
#> $`2`
#> Chromatographic data (Chromatograms) with 2 chromatograms in a ChromBackendMemory backend:
#> chromIndex msLevel mz
#> 3 NA 2 134.4
#> 4 NA 2 145.5
#> ... 2 more chromatogram variables/columns
#> ... 2 peaksData variables
#> Processing:
#> Merged 2 Chromatograms into one [Tue Aug 18 12:08:12 2026]
#>