% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/validate_sframe.R
\name{validate_sframe}
\alias{validate_sframe}
\title{Validate an instrument object}
\usage{
validate_sframe(instrument, strict = TRUE)
}
\arguments{
\item{instrument}{An \code{sframe} object created by \code{\link[=sf_instrument]{sf_instrument()}}.}

\item{strict}{Logical. When \code{TRUE} (default), any detected problem raises
an error of class \code{sframe_validation_error}. When \code{FALSE}, problems are
returned as a character vector of messages without stopping.}
}
\value{
When \code{strict = TRUE} and the instrument is valid, the instrument
is returned invisibly with \code{meta$validated} set to \code{TRUE}. When
\code{strict = FALSE}, a named list with elements \code{valid} (logical) and
\code{problems} (character vector) is returned.
}
\description{
Checks the internal consistency of an \code{sframe} instrument object and
reports all detected problems. Validation is performed automatically by
\code{\link[=write_sframe]{write_sframe()}} and optionally by \code{\link[=read_sframe]{read_sframe()}}. It can also be run
independently at any point during instrument construction.
}
\details{
The following checks are performed:
\itemize{
\item Duplicate item IDs
\item Invalid item IDs
\item Duplicate choice-set IDs
\item Duplicate scale IDs
\item Items with missing labels
\item Items referencing a missing \code{choice_set} in the instrument
\item Items referencing a missing \code{scale_id} in the instrument
\item Items marked \code{reverse = TRUE} without a \code{scale_id}
\item Choice sets referenced by items but not present in the instrument
\item Scale \code{items} vectors containing IDs not present in the instrument
\item Branching rules referencing item IDs not present in the instrument
\item Attention checks referencing item IDs not present in the instrument
\item Analysis plan roles referencing missing variables or models
\item Model specifications referencing missing indicators or constructs
}
}
\examples{
# Build a minimal valid instrument and validate it
cs    <- sf_choices("ag5", 1:5,
           c("Strongly disagree", "Disagree", "Neutral",
             "Agree", "Strongly agree"))
item  <- sf_item("sat_1", "The service met my expectations.",
                 type = "likert", choice_set = "ag5", scale_id = "sat")
scale <- sf_scale("sat", "Satisfaction", items = "sat_1")
instr <- sf_instrument("Demo Survey", components = list(cs, item, scale))

# Non-strict: returns a list without stopping
result <- validate_sframe(instr, strict = FALSE)
result$valid
result$problems

# Strict: returns instrument invisibly when valid
validated <- validate_sframe(instr, strict = TRUE)
isTRUE(validated$meta$validated)
}
\seealso{
\code{\link[=sf_instrument]{sf_instrument()}}, \code{\link[=write_sframe]{write_sframe()}}
}
