Checks the internal consistency of an sframe instrument object and
reports all detected problems. Validation is performed automatically by
write_sframe() and optionally by read_sframe(). It can also be run
independently at any point during instrument construction.
Arguments
- instrument
An
sframeobject created bysf_instrument().- strict
Logical. When
TRUE(default), any detected problem raises an error of classsframe_validation_error. WhenFALSE, problems are returned as a character vector of messages without stopping.
Value
When strict = TRUE and the instrument is valid, the instrument
is returned invisibly with meta$validated set to TRUE. When
strict = FALSE, a named list with elements valid (logical) and
problems (character vector) is returned.
Details
The following checks are performed:
Duplicate item IDs
Invalid item IDs
Duplicate choice-set IDs
Duplicate scale IDs
Items with missing labels
Items referencing a missing
choice_setin the instrumentItems referencing a missing
scale_idin the instrumentItems marked
reverse = TRUEwithout ascale_idChoice sets referenced by items but not present in the instrument
Scale
itemsvectors containing IDs not present in the instrumentBranching rules referencing item IDs not present in the instrument
Attention checks referencing item IDs not present in the instrument
Analysis plan roles referencing missing variables or models
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
#> [1] TRUE
result$problems
#> character(0)
# Strict: returns instrument invisibly when valid
validated <- validate_sframe(instr, strict = TRUE)
isTRUE(validated$meta$validated)
#> [1] TRUE