This step
method for update()
takes named arguments as ...
who's values
will replace the elements of the same name in the actual step.
Usage
# S3 method for step
update(object, ...)
Arguments
- object
A recipe
step
.- ...
Key-value pairs where the keys match up with names of elements in the step, and the values are the new values to update the step with.
Details
For a step to be updated, it must not already have been trained. Otherwise,
conflicting information can arise between the data returned from
bake(object, new_data = NULL)
and the information in the step.
Examples
data(biomass, package = "modeldata")
biomass_tr <- biomass[biomass$dataset == "Training", ]
biomass_te <- biomass[biomass$dataset == "Testing", ]
# Create a recipe using step_bs() with degree = 3
rec <- recipe(
HHV ~ carbon + hydrogen + oxygen + nitrogen + sulfur,
data = biomass_tr
) %>%
step_bs(carbon, hydrogen, degree = 3)
# Update the step to use degree = 4
rec2 <- rec
rec2$steps[[1]] <- update(rec2$steps[[1]], degree = 4)
# Prep both recipes
rec_prepped <- prep(rec, training = biomass_tr)
rec2_prepped <- prep(rec2, training = biomass_tr)
# To see what changed
bake(rec_prepped, new_data = NULL)
#> # A tibble: 456 × 10
#> oxygen nitrogen sulfur HHV carbon_b…¹ carbo…² carbo…³ hydro…⁴ hydro…⁵
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 42.9 0.41 0 20.0 0.421 0.313 0.0775 0.385 0.365
#> 2 41.3 0.2 0 19.2 0.423 0.309 0.0754 0.381 0.369
#> 3 46.2 0.11 0.02 18.3 0.431 0.290 0.0651 0.374 0.376
#> 4 35.6 3.3 0.16 18.2 0.441 0.258 0.0504 0.420 0.315
#> 5 40.7 1 0.02 18.4 0.436 0.278 0.0590 0.399 0.348
#> 6 40.2 2.04 0.1 18.5 0.440 0.262 0.0519 0.378 0.372
#> 7 38.2 2.68 0.2 18.7 0.434 0.283 0.0613 0.362 0.388
#> 8 39.7 1.7 0.2 18.3 0.439 0.265 0.0534 0.381 0.369
#> 9 40.9 0.8 0 18.6 0.426 0.301 0.0710 0.393 0.355
#> 10 40 1.2 0.1 18.9 0.434 0.282 0.0609 0.368 0.382
#> # … with 446 more rows, 1 more variable: hydrogen_bs_3 <dbl>, and
#> # abbreviated variable names ¹carbon_bs_1, ²carbon_bs_2, ³carbon_bs_3,
#> # ⁴hydrogen_bs_1, ⁵hydrogen_bs_2
bake(rec2_prepped, new_data = NULL)
#> # A tibble: 456 × 12
#> oxygen nitrogen sulfur HHV carbon_b…¹ carbo…² carbo…³ carbo…⁴ hydro…⁵
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 42.9 0.41 0 20.0 0.322 0.359 0.178 0.0330 0.263
#> 2 41.3 0.2 0 19.2 0.325 0.357 0.174 0.0319 0.258
#> 3 46.2 0.11 0.02 18.3 0.344 0.347 0.156 0.0262 0.249
#> 4 35.6 3.3 0.16 18.2 0.371 0.325 0.127 0.0186 0.320
#> 5 40.7 1 0.02 18.4 0.355 0.339 0.144 0.0230 0.284
#> 6 40.2 2.04 0.1 18.5 0.368 0.328 0.130 0.0193 0.253
#> 7 38.2 2.68 0.2 18.7 0.350 0.342 0.149 0.0242 0.233
#> 8 39.7 1.7 0.2 18.3 0.365 0.331 0.133 0.0201 0.258
#> 9 40.9 0.8 0 18.6 0.333 0.353 0.166 0.0294 0.275
#> 10 40 1.2 0.1 18.9 0.351 0.342 0.148 0.0240 0.240
#> # … with 446 more rows, 3 more variables: hydrogen_bs_2 <dbl>,
#> # hydrogen_bs_3 <dbl>, hydrogen_bs_4 <dbl>, and abbreviated variable
#> # names ¹carbon_bs_1, ²carbon_bs_2, ³carbon_bs_3, ⁴carbon_bs_4,
#> # ⁵hydrogen_bs_1
# Cannot update a recipe step that has been trained!
if (FALSE) {
update(rec_prepped$steps[[1]], degree = 4)
}