% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/classificationQC.R
\name{classificationQC}
\alias{classificationQC}
\title{Perform quality control on a classification}
\usage{
classificationQC(
  classification,
  lengths,
  fullHierarchy = TRUE,
  labelUniqueness = TRUE,
  labelHierarchy = TRUE,
  singleChildCode = NULL,
  sequencing = NULL
)
}
\arguments{
\item{classification}{A \code{data.frame} containing (at least) two columns: the codes
and labels of the classification to be checked. This argument is mandatory.}

\item{lengths}{A \code{data.frame} with one row per hierarchical level giving the
        initial and final positions of the segment of the code referring
        to that level. The number of rows implicitly defines the number of hierarchical levels
(\eqn{k}). This argument is mandatory. The column names should be \code{charb} and \code{chare}, if this is not the case, they will be automatically changed and a warning will appear.}

\item{fullHierarchy}{Logical.
If \code{FALSE}, the function checks that all positions at levels greater
than 1 have a parent at the level immediately above (no orphans).  
If \code{TRUE}, it additionally checks that positions at levels strictly
lower than \eqn{k} have children in the next level (no childless nodes).}

\item{labelUniqueness}{Logical.
When \code{TRUE}, the function checks whether labels are unique at each
hierarchical level. Duplicates are listed in the
\code{QC_duplicatesLabel} table.}

\item{labelHierarchy}{Logical.
When \code{TRUE}, the function checks that:
\itemize{
  \item single children share the same label as their parent;
  \item if a parent shares a label with one of its children, it must be a
        single-child parent.
}}

\item{singleChildCode}{A \code{data.frame} specifying admissible codes for single
        children at each hierarchical level.
If not \code{NULL}, the function checks compliance with these codes.}

\item{sequencing}{A \code{data.frame} defining admissible codes and their expected
        order for multiple-child situations at each level.
If not \code{NULL}, the function checks sequencing consistency.}
}
\value{
A list of data frames flagging potential issues in the classification:
\itemize{
  \item \code{QC_output}: full augmented table with computed levels,
        code segments, and all compliance flags;
  \item \code{QC_noLevels}: rows for which hierarchical level could not be
        determined;
  \item \code{QC_orphan}: positions that lack an expected parent;
  \item \code{QC_childless}: positions expected to have children but do not;
  \item \code{QC_duplicatesLabel}: positions with duplicate labels within
        the same level;
  \item \code{QC_duplicatesCode}: duplicated codes;
  \item \code{QC_singleChildMismatch}: label inconsistencies for
        single-children relationships;
  \item \code{QC_singleCodeError}: single children with invalid codes (if
        \code{singleChildCode} is provided);
  \item \code{QC_multipleCodeError}: non-single children with invalid codes
        (if \code{sequencing} is provided);
  \item \code{QC_gapBefore}: missing expected codes in sequence;
  \item \code{QC_lastSibling}: flag for last sibling in sequencing rules.
}
}
\description{
This function performs a series of structural and logical quality-control
checks on a hierarchical classification. It verifies the consistency of the
hierarchical levels, the presence of parent–child relationships, the
uniqueness of labels, the compliance with admissible coding rules, and the
sequencing of children within each level.  
The output is a list of data frames flagging potential issues.
}
\examples{


classification <- read.csv(system.file("extdata/test", "Nace2_long.csv",
                                      package = "correspondenceTables"))
lengths <- data.frame(charb = c(1,2,3,5), chare = c(1,2,4,5))

Output <- classificationQC(
 classification = classification,
 lengths = lengths,
 fullHierarchy = TRUE,
 labelUniqueness = TRUE,
 labelHierarchy = TRUE,
 singleChildCode = NULL,
 sequencing = NULL
)

print(Output$QC_output)
print(Output$QC_orphan)
print(Output$QC_childless)
print(Output$QC_duplicatesLabel)
print(Output$QC_duplicatesCode)

}
