% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/merge_TATB.r
\name{merge_TATB}
\alias{merge_TATB}
\title{Merge TA and TB tables (haul-level catches)}
\usage{
merge_TATB(
  ta,
  tb,
  species,
  country = "all",
  strata = BioIndex::strata_scheme,
  wd = NA,
  save = FALSE,
  verbose = TRUE,
  rome_checks = FALSE
)
}
\arguments{
\item{ta}{A \code{data.frame} or \code{data.table} containing a full TA
dataset.}

\item{tb}{A \code{data.frame} or \code{data.table} containing a full TB
dataset.}

\item{species}{Character. Either a MEDITS 7-letter code, e.g.
\code{"ARISFOL"}, or \code{"all"}. If a species code is supplied, the first
4 characters are interpreted as \code{GENUS} and the last 3 as
\code{SPECIES}. If \code{species = "all"}, no species filter is applied to
TB and abundance/biomass indicators are returned by haul and species.}

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

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

\item{wd}{Working directory. If \code{NA}, a temporary directory is used.}

\item{save}{Logical. If \code{TRUE}, writes the merged table to
\code{file.path(wd, "output")}.}

\item{verbose}{Logical; if \code{TRUE}, prints progress messages.}

\item{rome_checks}{Logical; if \code{TRUE}, default, runs the internal
syntactic validation checks based on \code{RoME} version 0.2.3 logic. If
\code{FALSE}, skips these checks.}
}
\value{
A \code{data.frame} with TA metadata, TB catch totals and calculated
fields including mean position, swept area, depth stratum, \code{N_h},
\code{N_km2}, \code{kg_h} and \code{kg_km2}.
}
\description{
Combines haul-level operational data (TA) with species catch data (TB),
providing the essential foundation for calculating stratified abundance (N)
and biomass (kg) indices.
The function keeps only valid hauls, optionally performs quality checks
(times, positions, wing opening, haul/date consistency) using internal
validation functions based on \code{RoME} version 0.2.3, computes spatial
means, swept area, depth stratum, biomass/density indicators, and optionally
writes the merged data to disk.
}
\details{
The function follows the original BioIndex TA-TB merge workflow.

When \code{species = "all"}, all species records in TB are retained. The
output may therefore contain multiple rows for the same haul, one for each
species recorded in TB.

Setting \code{rome_checks = FALSE} only skips the RoME-like syntactic
validation block. The remaining merge logic is unchanged.
}
\examples{
data("TA", package = "BioIndex")
data("TB", package = "BioIndex")

m_tb <- merge_TATB(
  ta = TA,
  tb = TB,
  species = "ARISFOL",
  country = "ITA",
  wd = tempdir(),
  save = FALSE
)

m_tb_all <- merge_TATB(
  ta = TA,
  tb = TB,
  species = "all",
  country = "all",
  wd = tempdir(),
  save = FALSE,
  rome_checks = FALSE
)

}
