% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/verify.R
\name{as.data.frame.verify_stockflow}
\alias{as.data.frame.verify_stockflow}
\title{Convert verify() results to a data frame}
\usage{
\method{as.data.frame}{verify_stockflow}(
  x,
  row.names = NULL,
  optional = FALSE,
  which = c("tests", "sims")[1],
  direction = "long",
  test = NULL,
  label = NULL,
  ignore_case = TRUE,
  status = c("pass", "fail", "error", "skip"),
  condition = NULL,
  vars = NULL,
  type = NULL,
  ...
)
}
\arguments{
\item{x}{A \code{verify_stockflow} object (output of \code{\link[=verify]{verify()}}).}

\item{row.names}{\code{NULL} or a character vector giving row names (optional).}

\item{optional}{Ignored; present for compatibility.}

\item{which}{Character. \code{"tests"} (default) or \code{"sims"}. Partial matching
supported.}

\item{direction}{Character. \code{"long"} (default) or \code{"wide"}. Only used when
\code{which = "sims"}.}

\item{test}{Integer vector of test number(s) to display (1-based). Defaults to
\code{NULL} (show all tests). Can be combined with \code{label} (intersection).}

\item{label}{Character vector of regex patterns for partial, case-insensitive
label matching. A test is included if its label matches \emph{any} pattern.
E.g., \code{c("non-neg", "beta")} returns tests matching either fragment.
Can be combined with \code{test} (intersection).}

\item{ignore_case}{Logical; whether \code{label} matching is case-insensitive.
Default \code{TRUE}.}

\item{status}{Optional character vector of statuses to include (e.g.,
\code{c("fail", "error")}). Defaults to all statuses.
\itemize{
\item \code{which = "tests"}: filters rows by test status.
\item \code{which = "sims"}: filters to conditions that have at least one test
with a matching status.
}}

\item{condition}{Optional integer vector of condition numbers to filter by.
For \code{which = "sims"}, keeps only the matching condition simulations.
For \code{which = "tests"}, keeps only tests belonging to those conditions.}

\item{vars}{Variable names to retain in the data frame. Only applies when
\code{which = "sims"}. Defaults to \code{NULL} to include all variables.}

\item{type}{Variable types to retain in the data frame. Must be one or more of
'stock', 'flow', 'constant', 'aux', 'lookup', or 'func'. Only applies when
\code{which = "sims"}. Defaults to \code{NULL} to include all types.}

\item{...}{Additional arguments (unused).}
}
\value{
A \code{data.frame}. Column set depends on \code{which}:
\itemize{
\item \code{"tests"}: \code{test}, \code{label}, \code{status}, \code{outcome}, \code{expr_str}, \code{condition}, \code{conditions},
\code{message}.
\item \code{"sims"} (long): \code{test}, \code{condition}, \code{conditions}, \code{time}, \code{variable}, \code{value}.
\item \code{"sims"} (wide): \code{test}, \code{condition}, \code{conditions}, \code{time}, then one column per variable.
}
}
\description{
Converts a \code{verify_stockflow} object to a data frame.
}
\details{
\strong{\code{which = "tests"} (default)} returns one row per unit test with columns
\code{test}, \code{label}, \code{status}, \code{outcome}, \code{expr_str}, \code{conditions}, and \code{message}.
Use \code{test}, \code{label}, and \code{status} to filter.

\strong{\code{which = "sims"}} returns the underlying simulation time-series in long
format with columns \code{test} (test number(s) that used this simulation, as a
comma-separated string), \code{conditions} (specified conditions per test, if any),
\code{time}, \code{variable}, and \code{value}. Each unique condition generates one
simulation; if multiple tests share a condition their numbers are combined
in \code{test} (e.g. \code{"1, 3"}). When filtering with \code{test}, the displayed \code{test} value
shows only the requested matching test number(s) for the retained simulation
row(s). Use \code{direction = "wide"} to pivot variables into columns.
}
\examples{
# Create model with 2 unit tests
sfm <- stockflow("sir") |>
  unit_test(expr = all(susceptible >= 0)) |>
  # Add test with conditions
  unit_test(
    label = "lower infection rate",
    expr = all(susceptible >= 0),
    conditions = list(infection_rate = 0.1)
  )
res <- verify(sfm)

# Test results (default)
as.data.frame(res)

# Simulation time-series (long format)
as.data.frame(res, which = "sims") |> head()

# Simulation time-series (wide format)
as.data.frame(res, which = "sims", direction = "wide") |> head()

# Filter to simulation for test 2 only
as.data.frame(res, which = "sims", test = 2) |> head()

# Only simulations for passing tests
as.data.frame(res, which = "sims", status = "pass") |> head()
}
\concept{unitTest}
