| Title: | Neutral Versioned Form Definitions and Workbook Layouts |
|---|---|
| Description: | Loads explicit YAML resources describing versioned forms, fields, declarative constraints, reference requirements, and workbook layouts. Checks model definitions against an installed YAML schema and consistency rules, and provides value-like inspection APIs. Does not validate submitted data or connect to external services. |
| Authors: | Tony Chemit [aut, cre] |
| Maintainer: | Tony Chemit <[email protected]> |
| License: | LGPL-2.1 |
| Version: | 0.3.2 |
| Built: | 2026-11-07 01:09:08 UTC |
| Source: | https://github.com/cran/form.model |
Construct a checked model
as_form_model(definition, resource = "<list>")as_form_model(definition, resource = "<list>")
definition |
Named list following |
resource |
Source label for diagnostics. |
The definition as a form_model list, without the source label.
Invalid definitions raise model_form_error with diagnostics.
model <- read_form_model("examples/survey-form.yaml", "form.model") as_form_model(form_definition(model))model <- read_form_model("examples/survey-form.yaml", "form.model") as_form_model(form_definition(model))
Check a form definition
check_form_model(definition, resource = "<list>")check_form_model(definition, resource = "<list>")
definition |
Named list following |
resource |
Source label for diagnostics. |
Checks schema structure, then model consistency if structure passes.
Invalid definitions return diagnostics; invalid arguments raise model_form_error.
Submitted data is not checked.
A form_model_check with valid and a diagnostics data frame
containing resource, path and message columns.
model <- read_form_model("examples/survey-form.yaml", "form.model") check_form_model(form_definition(model))model <- read_form_model("examples/survey-form.yaml", "form.model") check_form_model(form_definition(model))
Get the complete definition
form_definition(model)form_definition(model)
model |
A checked |
Accessors preserve declaration order and do not revalidate models.
Treat checked models as read-only. Invalid model arguments raise model_form_error.
An ordinary list with schema_version, form, references and sheets.
model <- read_form_model("examples/survey-form.yaml", "form.model") form_definition(model)$formmodel <- read_form_model("examples/survey-form.yaml", "form.model") form_definition(model)$form
Get one field
form_field(model, id)form_field(model, id)
model |
A checked |
id |
Exact |
One definition as returned by form_fields(). Unknown IDs raise model_form_error.
model <- read_form_model("examples/survey-form.yaml", "form.model") form_field(model, "Observations.unit")$enummodel <- read_form_model("examples/survey-form.yaml", "form.model") form_field(model, "Observations.unit")$enum
Get fields in declaration order
form_fields(model, sheet = NULL)form_fields(model, sheet = NULL)
model |
A checked |
sheet |
Exact worksheet name, or |
Adds field IDs, names, sheet names and numeric coordinates.
Omitted mandatory becomes FALSE; reference shorthand becomes a mapping
with severity "error" when omitted. Other undeclared properties stay absent.
Use form_definition() for the original declarations.
Field definitions named <sheet>.<field>. Unknown sheets raise model_form_error.
model <- read_form_model("examples/survey-form.yaml", "form.model") form_fields(model, sheet = "Observations")model <- read_form_model("examples/survey-form.yaml", "form.model") form_fields(model, sheet = "Observations")
Get a sheet layout
form_layout(model, id)form_layout(model, id)
model |
A checked |
id |
Exact worksheet name. |
The effective layout (cells or table), with table column_count
derived from the fields. Unknown sheets raise model_form_error.
model <- read_form_model("examples/survey-form.yaml", "form.model") form_layout(model, "Observations")model <- read_form_model("examples/survey-form.yaml", "form.model") form_layout(model, "Observations")
Get form identity and versions
form_metadata(model)form_metadata(model)
model |
A checked |
A list with form and schema_version.
model <- read_form_model("examples/survey-form.yaml", "form.model") form_metadata(model)model <- read_form_model("examples/survey-form.yaml", "form.model") form_metadata(model)
Get reference requirements
form_references(model)form_references(model)
model |
A checked |
Declared reference names. Reference data is not loaded.
model <- read_form_model("examples/survey-form.yaml", "form.model") form_references(model)model <- read_form_model("examples/survey-form.yaml", "form.model") form_references(model)
Locate an installed resource
form_resource(path, package)form_resource(path, package)
path |
File path relative to the package directory. |
package |
Installed package name. |
Absolute file path. Missing files and paths escaping the package
raise model_form_error.
form_resource("examples/survey-form.yaml", "form.model")form_resource("examples/survey-form.yaml", "form.model")
Read the model-definition schema
form_schema(version = "1.0.0")form_schema(version = "1.0.0")
version |
Schema version; currently |
Uses the package's form.model/schema/1 dialect, not JSON Schema.
The schema as a nested list. Unsupported versions raise model_form_error.
form_schema()$contract_versionform_schema()$contract_version
Get sheet definitions
form_sheets(model)form_sheets(model)
model |
A checked |
Table layouts include column_count derived from the ordered fields.
Use form_definition() for the original declarations.
Sheets in declaration order, named by worksheet, each with fields and layout.
model <- read_form_model("examples/survey-form.yaml", "form.model") names(form_sheets(model))model <- read_form_model("examples/survey-form.yaml", "form.model") names(form_sheets(model))
Share field-type checks between model definitions and validation consumers. Requiredness and other field constraints are handled by the caller.
form_value_matches_type(x, type)form_value_matches_type(x, type)
x |
Scalar value to check, without coercion. |
type |
One of |
Dates require YYYY-MM-DD; datetimes require YYYY-MM-DDTHH:MM:SSZ.
Both must parse and format back to the identical string, using UTC for
datetimes. Emails require nonempty local and domain parts, a domain dot,
and no whitespace or additional at signs. Mailbox existence is not checked.
Numeric values must be finite; integers must have no fractional part.
Coordinates are decimal degrees: latitude is in [-90, 90] and longitude
in [-180, 180], including both endpoints. Numeric text is not coerced.
One logical value; FALSE for missing or incompatible values,
unsupported types, or classed values such as factors, Date, and POSIXct.
form_value_matches_type("[email protected]", "email") form_value_matches_type("2026-10-18T12:00:00Z", "datetime")form_value_matches_type("[email protected]", "email") form_value_matches_type("2026-10-18T12:00:00Z", "datetime")
Load a model by filename prefix
load_form_model(name, directory)load_form_model(name, directory)
name |
Prefix of |
directory |
Directory containing the file. |
A checked form_model; see read_form_model() for errors.
directory <- system.file("examples", package = "form.model") load_form_model("survey", directory)directory <- system.file("examples", package = "form.model") load_form_model("survey", directory)
Print a model summary
## S3 method for class 'form_model' print(x, ...)## S3 method for class 'form_model' print(x, ...)
x |
A checked |
... |
Unused. |
x, invisibly; prints identity, versions, and field and sheet counts.
Print definition check results
## S3 method for class 'form_model_check' print(x, ...)## S3 method for class 'form_model_check' print(x, ...)
x |
A |
... |
Unused. |
x, invisibly; prints validity and any diagnostics.
Read and check a YAML form model
read_form_model(path, package = NULL)read_form_model(path, package = NULL)
path |
File path, or package-relative path when |
package |
Optional installed package name. |
Uses YAML 1.1 types: quote versions and codes; use true/false
for booleans. Tags, anchors, aliases, merges, directives and document markers
are unsupported. The source path is not stored in the model.
A checked form_model list. Invalid YAML or definitions raise
model_form_error with source context and available diagnostics.
model <- read_form_model("examples/survey-form.yaml", "form.model") form_metadata(model)model <- read_form_model("examples/survey-form.yaml", "form.model") form_metadata(model)
Select an exact model version
select_form_model(paths, id, version, package = NULL)select_form_model(paths, id, version, package = NULL)
paths |
Nonempty character vector of YAML file paths. |
id |
Exact form identifier. |
version |
Exact form version. |
package |
Optional installed package containing the relative paths. |
The matching form_model. All files are checked; invalid files or
anything other than one match raise model_form_error.
select_form_model("examples/survey-form.yaml", "survey", "2026.1", package = "form.model")select_form_model("examples/survey-form.yaml", "survey", "2026.1", package = "form.model")