@@ -95,23 +95,10 @@ add_epi_recipe <- function(
95
95
# ' @rdname add_epi_recipe
96
96
# ' @export
97
97
remove_epi_recipe <- function (x ) {
98
- workflows ::: validate_is_workflow(x )
99
-
100
- if (! workflows ::: has_preprocessor_recipe(x )) {
101
- rlang :: warn(" The workflow has no recipe preprocessor to remove." )
102
- }
103
-
104
- actions <- x $ pre $ actions
105
- actions [[" recipe" ]] <- NULL
106
-
107
- new_epi_workflow(
108
- pre = workflows ::: new_stage_pre(actions = actions ),
109
- fit = x $ fit ,
110
- post = x $ post ,
111
- trained = FALSE
112
- )
98
+ workflows :: remove_recipe(x )
113
99
}
114
100
101
+
115
102
# ' @rdname add_epi_recipe
116
103
# ' @export
117
104
update_epi_recipe <- function (x , recipe , ... , blueprint = default_epi_recipe_blueprint()) {
@@ -180,15 +167,21 @@ adjust_epi_recipe <- function(x, which_step, ..., blueprint = default_epi_recipe
180
167
181
168
# ' @rdname adjust_epi_recipe
182
169
# ' @export
183
- adjust_epi_recipe.epi_workflow <- function (x , which_step , ... , blueprint = default_epi_recipe_blueprint()) {
184
- recipe <- adjust_epi_recipe(workflows :: extract_preprocessor(x ), which_step , ... )
170
+ adjust_epi_recipe.epi_workflow <- function (
171
+ x , which_step , ... , blueprint = default_epi_recipe_blueprint()
172
+ ) {
185
173
186
- update_epi_recipe(x , recipe , blueprint = blueprint )
174
+ rec <- adjust_epi_recipe(
175
+ workflows :: extract_preprocessor(x ), which_step , ...
176
+ )
177
+ update_epi_recipe(x , rec , blueprint = blueprint )
187
178
}
188
179
189
180
# ' @rdname adjust_epi_recipe
190
181
# ' @export
191
- adjust_epi_recipe.epi_recipe <- function (x , which_step , ... , blueprint = default_epi_recipe_blueprint()) {
182
+ adjust_epi_recipe.epi_recipe <- function (
183
+ x , which_step , ... , blueprint = default_epi_recipe_blueprint()
184
+ ) {
192
185
if (! (is.numeric(which_step ) || is.character(which_step ))) {
193
186
cli :: cli_abort(
194
187
c(" `which_step` must be a number or a character." ,
@@ -294,109 +287,17 @@ kill_levels <- function(x, keys) {
294
287
295
288
# ' @export
296
289
print.epi_recipe <- function (x , form_width = 30 , ... ) {
297
- cli :: cli_div(theme = list (.pkg = list (" vec-trunc" = Inf , " vec-last" = " , " )))
298
-
299
- cli :: cli_h1(" Epi Recipe" )
300
- cli :: cli_h3(" Inputs" )
301
-
302
- tab <- table(x $ var_info $ role , useNA = " ifany" )
303
- tab <- stats :: setNames(tab , names(tab ))
304
- names(tab )[is.na(names(tab ))] <- " undeclared role"
305
-
306
- roles <- c(" outcome" , " predictor" , " case_weights" , " undeclared role" )
307
-
308
- tab <- c(
309
- tab [names(tab ) == roles [1 ]],
310
- tab [names(tab ) == roles [2 ]],
311
- tab [names(tab ) == roles [3 ]],
312
- sort(tab [! names(tab ) %in% roles ], TRUE ),
313
- tab [names(tab ) == roles [4 ]]
314
- )
315
-
316
- cli :: cli_text(" Number of variables by role" )
317
-
318
- spaces_needed <- max(nchar(names(tab ))) - nchar(names(tab )) +
319
- max(nchar(tab )) - nchar(tab )
320
-
321
- cli :: cli_verbatim(
322
- glue :: glue(" {names(tab)}: {strrep('\u a0', spaces_needed)}{tab}" )
323
- )
324
-
325
- if (" tr_info" %in% names(x )) {
326
- cli :: cli_h3(" Training information" )
327
- nmiss <- x $ tr_info $ nrows - x $ tr_info $ ncomplete
328
- nrows <- x $ tr_info $ nrows
329
-
330
- cli :: cli_text(
331
- " Training data contained {nrows} data points and {cli::no(nmiss)} \\
332
- incomplete row{?s}."
333
- )
334
- }
335
-
336
- if (! is.null(x $ steps )) {
337
- cli :: cli_h3(" Operations" )
338
- }
339
-
340
- fmt <- cli :: cli_fmt({
341
- for (step in x $ steps ) {
342
- print(step , form_width = form_width )
343
- }
344
- })
345
- cli :: cli_ol(fmt )
346
- cli :: cli_end()
347
-
348
- invisible (x )
349
- }
350
-
351
- # Currently only used in the workflow printing
352
- print_preprocessor_recipe <- function (x , ... ) {
353
- recipe <- workflows :: extract_preprocessor(x )
354
- steps <- recipe $ steps
355
- n_steps <- length(steps )
356
- cli :: cli_text(" {n_steps} Recipe step{?s}." )
357
-
358
- if (n_steps == 0L ) {
359
- return (invisible (x ))
360
- }
361
-
362
- step_names <- map_chr(steps , workflows ::: pull_step_name )
363
-
364
- if (n_steps < = 10L ) {
365
- cli :: cli_ol(step_names )
366
- return (invisible (x ))
367
- }
368
-
369
- extra_steps <- n_steps - 10L
370
- step_names <- step_names [1 : 10 ]
371
-
372
- cli :: cli_ol(step_names )
373
- cli :: cli_bullets(" ... and {extra_steps} more step{?s}." )
374
- invisible (x )
375
- }
376
-
377
- print_preprocessor <- function (x ) {
378
- has_preprocessor_formula <- workflows ::: has_preprocessor_formula(x )
379
- has_preprocessor_recipe <- workflows ::: has_preprocessor_recipe(x )
380
- has_preprocessor_variables <- workflows ::: has_preprocessor_variables(x )
381
-
382
- no_preprocessor <- ! has_preprocessor_formula && ! has_preprocessor_recipe &&
383
- ! has_preprocessor_variables
384
-
385
- if (no_preprocessor ) {
386
- return (invisible (x ))
387
- }
388
-
389
- cli :: cli_rule(" Preprocessor" )
390
- cli :: cli_text(" " )
391
-
392
- if (has_preprocessor_formula ) {
393
- workflows ::: print_preprocessor_formula(x )
394
- }
395
- if (has_preprocessor_recipe ) {
396
- print_preprocessor_recipe(x )
397
- }
398
- if (has_preprocessor_variables ) {
399
- workflows ::: print_preprocessor_variables(x )
400
- }
290
+ o <- cli :: cli_fmt(NextMethod())
291
+ # Fix up the recipe name
292
+ rr <- unlist(strsplit(o [2 ], " Recipe" ))
293
+ len <- nchar(rr [2 ])
294
+ h1_tail <- paste0(substr(rr [2 ], 1 , len / 2 - 10 ), substr(rr [2 ], len / 2 , len ))
295
+ o [2 ] <- paste0(rr [1 ], " Epi Recipe" , h1_tail )
296
+
297
+ # Number the operations
298
+ ops <- seq(grep(" Operations " , o , fixed = TRUE ) + 1 , length(o ))
299
+ rep_ops <- sub(" \0 33[36m•\0 33[39m " , " " , o [ops ], fixed = TRUE ) # kills the •
300
+ o [ops ] <- paste0(ops - ops [1 ] + 1 , " . " , rep_ops )
301
+ cli :: cli_bullets(o )
401
302
invisible (x )
402
303
}
0 commit comments