Skip to content

Commit 0039a4f

Browse files
committed
bullets --> numbers in epi_workflow printed steps and frosting
1 parent 2dd9e70 commit 0039a4f

File tree

2 files changed

+101
-8
lines changed

2 files changed

+101
-8
lines changed

R/epi_recipe.R

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,75 @@ kill_levels <- function(x, keys) {
397397
for (i in which(names(x) %in% keys)) x[[i]] <- list(values = NA, ordered = NA)
398398
x
399399
}
400+
401+
print_preprocessor_recipe <- function (x) {
402+
403+
recipe <- workflows::extract_preprocessor(x)
404+
steps <- recipe$steps
405+
n_steps <- length(steps)
406+
if (n_steps == 1L) {
407+
step <- "Step"
408+
}
409+
else {
410+
step <- "Steps"
411+
}
412+
n_steps_msg <- glue::glue("{n_steps} Recipe {step}")
413+
cat_line(n_steps_msg)
414+
415+
if (n_steps == 0L) return(invisible(x))
416+
417+
cat_line("")
418+
419+
step_names <- map_chr(steps, workflows:::pull_step_name)
420+
421+
if (n_steps <= 10L) {
422+
cli:::cli_ol(step_names)
423+
return(invisible(x))
424+
}
425+
426+
extra_steps <- n_steps - 10L
427+
step_names <- step_names[1:10]
428+
429+
if (extra_steps == 1L) {
430+
step <- "step"
431+
}
432+
else {
433+
step <- "steps"
434+
}
435+
436+
extra_dots <- "..."
437+
extra_msg <- glue::glue("and {extra_steps} more {step}.")
438+
439+
cli::cli_ol(step_names)
440+
cli::cli_bullets(c(extra_dots, extra_msg))
441+
invisible(x)
442+
}
443+
444+
print_preprocessor <- function(x) {
445+
446+
has_preprocessor_formula <- workflows:::has_preprocessor_formula(x)
447+
has_preprocessor_recipe <- workflows:::has_preprocessor_recipe(x)
448+
has_preprocessor_variables <- workflows:::has_preprocessor_variables(x)
449+
450+
no_preprocessor <- !has_preprocessor_formula && !has_preprocessor_recipe &&
451+
!has_preprocessor_variables
452+
453+
if (no_preprocessor) {
454+
return(invisible(x))
455+
}
456+
457+
cat_line("")
458+
header <- cli::rule("Preprocessor")
459+
cat_line(header)
460+
461+
if (has_preprocessor_formula) {
462+
workflows:::print_preprocessor_formula(x)
463+
}
464+
if (has_preprocessor_recipe) {
465+
print_preprocessor_recipe(x)
466+
}
467+
if (has_preprocessor_variables) {
468+
workflows:::print_preprocessor_variables(x)
469+
}
470+
invisible(x)
471+
}

R/frosting.R

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,36 @@ apply_frosting.epi_workflow <-
269269
}
270270

271271
#' @export
272-
print.frosting <- function(x, form_width = 30, ...) {
273-
cli::cli_div(
274-
theme = list(.pkg = list(`vec-trunc` = Inf, `vec-last` = ", "))
275-
)
276-
cli::cli_h1("Frosting")
272+
# Currently only used in the workflow printing
273+
print_frosting <- function(x, ...) {
274+
275+
layers <- x$layers
276+
n_layers <- length(layers)
277+
layer <- ifelse(n_layers == 1L, "Layer", "Layers")
278+
n_layers_msg <- glue::glue("{n_layers} Frosting {layer}")
279+
cat_line(n_layers_msg)
280+
281+
if (n_layers == 0L) return(invisible(x))
282+
283+
cat_line("")
284+
285+
layer_names <- map_chr(layers, pull_layer_name)
286+
287+
if (n_layers <= 10L) {
288+
cli:::cli_ol(layer_names)
289+
return(invisible(x))
290+
}
291+
292+
extra_layers <- n_layers - 10L
293+
layer_names <- layer_names[1:10]
294+
295+
layer <- ifelse(extra_layers == 1L, "layer", "layers")
296+
297+
extra_dots <- "..."
298+
extra_msg <- glue::glue("and {extra_layers} more {layer}.")
277299

278-
if (!is.null(x$layers)) cli::cli_h3("Layers")
279-
for (layer in x$layers) print(layer, form_width = form_width)
280-
cli::cli_end()
300+
cli::cli_ol(layer_names)
301+
cli::cli_bullets(c(extra_dots, extra_msg))
281302
invisible(x)
282303
}
283304

0 commit comments

Comments
 (0)