Fail-closed validation of a roles tibble before mask() consumes it.
Errors are raised for every misuse the v0.2 spec calls out.
Arguments
- roles
A tibble produced by
propose_roles()(possibly edited).- df
Optional data frame. If supplied,
rolesis checked for one-to-one column-name correspondence withdf.
Details
Hard errors:
missing required columns (
col,role,kind);unknown role string (not in
c("design","treatment","outcome","covariate","ignore"));any
NArole;zero columns flagged
outcome;more than one column flagged
treatment(joint-treatment masking is not yet supported bymask());duplicate
colentries;if
dfsupplied: anydfcolumn missing fromroles, or anyrolescolumn missing fromdf.
Returns the validated roles invisibly (mirrors stopifnot-style use).
Examples
r <- propose_roles(iris)
r$role[r$col == "Sepal.Length"] <- "outcome"
roles_validate(r, iris)