% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/Chromatograms.R
\name{concatenateChromatograms}
\alias{concatenateChromatograms}
\alias{c,Chromatograms-method}
\alias{split,Chromatograms,ANY-method}
\title{Merging, combining and splitting Chromatograms}
\usage{
concatenateChromatograms(x, ...)

\S4method{c}{Chromatograms}(x, ...)

\S4method{split}{Chromatograms,ANY}(x, f, drop = FALSE, ...)
}
\arguments{
\item{x}{A \code{Chromatograms} object.}

\item{...}{For \code{c()} and \code{concatenateChromatograms()}: \code{Chromatograms}
objects or a \code{list} of \code{Chromatograms} objects.}

\item{f}{\code{factor} defining the grouping to split the \code{Chromatograms} object.}

\item{drop}{For \code{split()}: not considered.}
}
\value{
\itemize{
\item \code{c()} and \code{concatenateChromatograms()}: a single \code{Chromatograms} object
containing the data from all input objects.
\item \code{split()}: a \code{list} of \code{Chromatograms} objects.
}
}
\description{
Various functions are available to combine or split data from one or more
\code{Chromatograms} objects. These are:
\itemize{
\item \code{c()} and \code{concatenateChromatograms()}: combines several \code{Chromatograms}
objects into a single object. The resulting \code{Chromatograms} contains all
data from all individual \code{Chromatograms}, i.e. the union of all their
chromatograms variables. Concatenation will fail if the processing queue
of any of the \code{Chromatograms} objects is not empty or if different backends
are used for the \code{Chromatograms} objects. In such cases it is suggested to
first change the backends of all \code{Chromatograms} to the same type of
backend (using the \code{\link[ProtGenerics:backendInitialize]{ProtGenerics::setBackend()}} function) and to eventually (if needed)
apply the processing queue using the \code{\link[ProtGenerics:processingQueue]{ProtGenerics::applyProcessing()}} function.
\item \code{split()}: splits the \code{Chromatograms} object based on a provided grouping
factor returning a \code{list} of \code{Chromatograms} objects.
}
}
\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

## 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

}
