R: Manually Add Roles

add_role {recipes} | R Documentation

## Manually Add Roles

### Description

`add_role` can add a role definition to an existing variable in the recipe.

### Usage

    add_role(recipe, ..., new_role = "predictor")

### Arguments

`recipe` | An existing `recipe()`.
`...` | One or more selector functions to choose which variables are being assigned a role. See `selections()` for more details.
`new_role` | A character string for a single role.

### Details

If a variable is selected that currently has a role, the role is changed and a warning is issued.

### Value

An updated recipe object.

### Examples

    data(biomass)

    # Create the recipe manually
    rec <- recipe(x = biomass)
    rec
    summary(rec)

    rec <- rec %>%
      add_role(carbon, contains("gen"), sulfur, new_role = "predictor") %>%
      add_role(sample, new_role = "id variable") %>%
      add_role(dataset, new_role = "splitting variable") %>%
      add_role(HHV, new_role = "outcome")
    rec

[Package recipes version 0.1.2 Index]