Fail-closed validation of a two-axis roles table before mask()
consumes it. Returns the validated table - with any NA actions
resolved to their (role, kind, mode) defaults - so callers can use
the return value directly.
Arguments
- roles
A roles table from
propose_roles()(possibly edited), or a v1 roles tibble (deprecated, upgraded with a warning).- df
Optional data frame. If supplied,
rolesis checked for one-to-one column-name correspondence withdf.- mode
Optional mode (
"local"or"collaborate") used to resolveNAactions and to upgrade v1 tables. Defaults toattr(roles, "mode"), falling back to"local".
Details
Tables produced by masque 0.5.0 and earlier (no action column;
v1 vocabulary with keep / ignore roles and the optional
mask_levels column) are upgraded in place with a deprecation
warning. The upgrade preserves the v1 semantics exactly: v1 keep
becomes action keep; v1 ignore becomes role id / text /
other with action keep in local mode and drop in collaborate
mode; v1 treatment mask_levels = "permute" becomes action
scramble.
Hard errors:
missing required columns (
col,role,action,kind);unknown role (not in
design,treatment,outcome,covariate,date,id,text,other) or unknown action (not inkeep,scramble,alias,drop);any
NArole (anNAaction is allowed - it resolves to the default for the row's role and kind);an incompatible (role, action, kind) combination, e.g.
design+scramble, numeric +alias,id+scramble,other+ anything but keep / drop;duplicate
colentries;if
dfsupplied: anydfcolumn missing fromroles, or anyrolescolumn missing fromdf.
Loud advisories (warnings, not errors):
every action is
keep- the "synthetic" would equal the original byte-for-byte;the table was proposed for one mode but is being validated for another (actions are taken as-is; defaults are not re-resolved).
Examples
r <- propose_roles(iris)
r <- set_role(r, "Sepal.Length", role = "outcome")
roles_validate(r, iris)