Skip to contents

Fail-closed validation of a roles tibble before mask() consumes it. Errors are raised for every misuse the v0.2 spec calls out.

Usage

roles_validate(roles, df = NULL)

Arguments

roles

A tibble produced by propose_roles() (possibly edited).

df

Optional data frame. If supplied, roles is checked for one-to-one column-name correspondence with df.

Value

roles, invisibly.

Details

Hard errors:

  • missing required columns (col, role, kind);

  • unknown role string (not in c("design","treatment","outcome","covariate","ignore"));

  • any NA role;

  • zero columns flagged outcome;

  • more than one column flagged treatment (joint-treatment masking is not yet supported by mask());

  • duplicate col entries;

  • if df supplied: any df column missing from roles, or any roles column missing from df.

Returns the validated roles invisibly (mirrors stopifnot-style use).

See also

Examples

r <- propose_roles(iris)
r$role[r$col == "Sepal.Length"] <- "outcome"
roles_validate(r, iris)