Set the role and action of one or more columns in a roles table
Source:R/roles_actions.R
set_role.RdErgonomic editor for the two-axis roles table returned by
propose_roles(). Setting a role without an explicit action
re-resolves the action to the default for the new role, the column's
kind, and the mode the table was proposed for — so a re-roled column
never silently carries a stale action from its previous role.
Arguments
- roles
A roles table from
propose_roles()(possibly edited).- cols
Character vector of column names to edit. Every entry must be present in
roles$col.- role
Optional single role to assign to all of
cols. One of"design","treatment","outcome","covariate","date","id","text","other".- action
Optional single action to assign to all of
cols. One of"keep","scramble","alias","drop". WhenNULL(the default) androlewas supplied, the action is re-resolved to the default for the new role.
Details
Direct edits (roles$role[roles$col == "x"] <- "outcome") remain
fully supported; this helper exists because a direct role edit leaves
roles$action untouched, which is occasionally what you want and
frequently not.
Examples
r <- propose_roles(iris)
r <- set_role(r, "Sepal.Length", role = "outcome")
r <- set_role(r, "Species", action = "keep")
r[, c("col", "role", "action")]
#> # A tibble: 5 × 3
#> col role action
#> <chr> <chr> <chr>
#> 1 Sepal.Length outcome scramble
#> 2 Sepal.Width covariate scramble
#> 3 Petal.Length covariate scramble
#> 4 Petal.Width covariate scramble
#> 5 Species treatment keep