% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/pep_check_phases.R
\name{pep_check_phases}
\alias{pep_check_phases}
\title{Check for Expected Phenological Phases}
\usage{
pep_check_phases(
  pep,
  expected = NULL,
  species = NULL,
  year_min = NULL,
  year_max = NULL,
  warn = TRUE,
  label = "Data"
)
}
\arguments{
\item{pep}{A \code{pep} object or \code{data.table} containing phenological
observations with a \code{phase_id} column.}

\item{expected}{Integer vector of expected BBCH phase codes. If \code{NULL}
(default), checks for common phases: 10 (leaf), 60 (heading/flowering),
65 (full flowering), and 100 (harvest).}

\item{species}{Optional character string to filter by species/genus before
checking. If specified, only checks phases for this species.}

\item{year_min}{Optional integer. Only check phases for years >= this value.
Useful for checking data availability within an analysis window.}

\item{year_max}{Optional integer. Only check phases for years <= this value.}

\item{warn}{Logical. If \code{TRUE} (default), issues warnings for missing
phases. If \code{FALSE}, only returns the result silently.}

\item{label}{Character. Optional label to include in warning messages,
useful when checking multiple datasets. Default is \code{"Data"}.}
}
\value{
A list with class \code{phase_check} containing:
\describe{
\item{expected}{The expected phase codes}
\item{present}{Phase codes found in the data}
\item{missing}{Phase codes not found in the data}
\item{extra}{Phase codes in data but not in expected list}
\item{complete}{Logical. TRUE if all expected phases are present}
\item{n_obs}{Named integer vector of observation counts per present phase}
\item{coverage}{Data.table with phase-level statistics}
}
}
\description{
Validates that expected phenological phases (BBCH codes) are present in the
data. Issues informative warnings for missing phases without stopping
execution, making it useful for pipeline validation.
}
\details{
This function is designed to be used at the start of analysis pipelines
to validate that required phenological phases are available. It issues
warnings but does not stop execution, allowing users to be informed of
potential issues while still proceeding with available data.
}
\section{Common BBCH Phases}{

\describe{
\item{10}{Leaf development}
\item{60}{Beginning of flowering / Heading}
\item{65}{Full flowering / Anthesis}
\item{69}{End of flowering}
\item{87}{Hard dough (cereals)}
\item{100}{Harvest}
}
}

\examples{
\donttest{
pep <- pep_download()

# Use Swiss subset for faster checking
pep_ch <- pep[country == "Switzerland"]

# Basic check for common phases
check <- pep_check_phases(pep_ch)

# Check specific phases for grapevine (longest historical records)
check <- pep_check_phases(pep_ch,
                      expected = c(60, 65, 81),
                      species = "Vitis vinifera")

# Check within analysis window
check <- pep_check_phases(pep_ch,
                      expected = c(60, 65),
                      year_min = 1991,
                      year_max = 2020)

# Use in pipeline with custom label
vine_data <- pep_ch[species == "Vitis vinifera"]
if (nrow(vine_data) > 0) {
  pep_check_phases(vine_data, expected = c(60, 65),
               label = "Grapevine analysis")
}

# Silent check (no warnings)
result <- pep_check_phases(pep_ch, warn = FALSE)
if (!result$complete) {
  # Handle missing phases programmatically
}
}

}
\seealso{
\code{\link{bbch_description}} for phase code descriptions,
\code{\link{pep_completeness}} for detailed completeness assessment,
\code{\link{pep_quality}} for quality grading
}
\author{
Matthias Templ
}
