% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/merge_TATC.r
\name{merge_TATC}
\alias{merge_TATC}
\title{Merge TA and TC tables (haul-level lengthâ€“frequency data)}
\usage{
merge_TATC(
  ta,
  tc,
  species,
  country = "all",
  strata = BioIndex::strata_scheme,
  wd = NA,
  save = TRUE,
  verbose = TRUE
)
}
\arguments{
\item{ta}{A `data.frame`/`data.table` containing a full TA dataset
(columns listed in `BioIndex::TA_cols`).}

\item{tc}{A `data.frame`/`data.table` containing a full TC dataset
(columns listed in `BioIndex::TC_cols`).}

\item{species}{Character, MEDITS 7-letter code (e.g. `"ARISFOL"`).
The first 4 characters are interpreted as *GENUS* and
the last 3 as *SPECIES*.}

\item{country}{Character vector of ISO-3 country codes to keep; use
`"all"` (default) to keep every country present in `ta`.}

\item{strata}{Depth-stratum reference table; default is
`BioIndex::strata_scheme`.}

\item{wd}{Working directory.  If `NA` (the default when
`save=FALSE`) no files are written.}

\item{save}{Logical.  If `TRUE`, writes
`"mergeTATC_<GENUS><SPECIES>.csv"` to
`file.path(wd, "output")`.}

\item{verbose}{Logical; if `TRUE` (default) prints progress messages.}
}
\value{
A `data.frame` in which each row represents one length-class
        (and sex/maturity) sampled in a haul, including:
        * **TA** metadata
        * **TC** length-frequency counts and weights
        * Calculated fields: mean lat/lon, swept area, depth stratum,
          raising factor, density (`N_h`, `N_km2`) and biomass
          (`kg_h`, `kg_km2`)
}
\description{
Links haul metadata (TA) with length-frequency samples (TC),
enabling the analysis of population demographic structure and the
reconstruction of length-frequency distributions (LFD).
The function keeps only valid hauls, runs all relevant quality checks
(times, positions, wing opening, haul/date consistency) using internal
validation functions (based on \code{RoME} version 0.2.3),
computes swept area, depth stratum, raising factors,
abundance/biomass indicators, andâ€”optionallyâ€”writes the merged data.
}
\details{
The code is identical to the official BioIndex routine.

\strong{Data Validation:}
The function performs syntactic data validation using internal
implementations of the validation routines (based on \code{RoME} v0.2.3).

\strong{Optimisations:}
Includes two micro-optimisations: vectorised handling of missing `"NA NA"` entries
and a single depth-stratum loop. Numerical results remain unchanged.
}
\note{
This version of \code{BioIndex} uses internal validation functions based on
\strong{RoME version 0.2.3}. The package is fully self-sufficient and does
not require external validation packages to be installed.
}
\examples{
# Use internal data
data("TA", package = "BioIndex")
data("TC", package = "BioIndex")
m_tc <- merge_TATC(
  ta       = TA,
  tc       = TC,
  species  = "ARISFOL",
  country  = "ESP",
  wd       = tempdir(),
  save=FALSE
)
head(m_tc)
}
\seealso{
[BioIndex] package documentation.
}
