% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/df.R
\name{sch_df}
\alias{sch_df}
\alias{new_sch_df}
\alias{validate_sch_df}
\title{Construct and validate a schema-aware data frame}
\usage{
new_sch_df(data, schema, groups = NULL, class = NULL, use_tbl = TRUE)

validate_sch_df(x)
}
\arguments{
\item{data}{A data frame.}

\item{schema}{A `sch_schema` object.}

\item{groups}{A named list of character vectors of column names, for use
with [sch_multiple()].}

\item{class}{Additional classes to add to the object, in addition to "sch_df" and tibble/data.frame classes.}

\item{use_tbl}{If `TRUE`, the returned object will have tibble
classes `tbl_df` and `tbl` in addition to `data.frame`. As a reminder,
`tbl_df` affects the behavior of the object (slicing, row names, etc.),
while `tbl` affects printing only.}

\item{x}{A `sch_df` object.}
}
\value{
A data frame with class `c(class, "sch_df", ...)` and attributes
  `sch_schema` and `sch_groups`.

The input, if validation is successful.
}
\description{
Bare-bones constructor for a data frame with an attached schema. This function
should be called by package developers writing their own internal constructors.
The only checks are for the types of `data` and `schema`.
The `validate_sch_df()` is a lightweight wrapper around [sch_validate()] that
also returns the input.
}
\examples{
schema = sch_schema(
    .desc = "MCMC draws",
    .relationships = ~ chain * draw * parameter,
    chain = sch_integer("Chain number"),
    draw = sch_integer("Draw number", bounds = c(1, Inf), closed = c(TRUE, FALSE)),
    parameter = sch_character("Parameter name"),
    value = sch_numeric("Parameter value")
)
d_raw = data.frame(chain = 1L, draw = 1:4, parameter = "mu", value = rnorm(4))
d = new_sch_df(d_raw, schema, class="mcmc_draws")
validate_sch_df(d)
str(d)
}
