Skip to content

Commit 03ae9a9

Browse files
committed
Enumerate in print.epi_recipe and print.frosting funs
1 parent 8aec6b5 commit 03ae9a9

File tree

5 files changed

+79
-7
lines changed

5 files changed

+79
-7
lines changed

NAMESPACE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ S3method(print,alist)
5252
S3method(print,arx_class)
5353
S3method(print,arx_fcast)
5454
S3method(print,canned_epipred)
55+
S3method(print,epi_recipe)
5556
S3method(print,epi_workflow)
5657
S3method(print,flat_fcast)
5758
S3method(print,flatline)
59+
S3method(print,frosting)
5860
S3method(print,layer_add_forecast_date)
5961
S3method(print,layer_add_target_date)
6062
S3method(print,layer_naomit)
@@ -144,8 +146,6 @@ export(new_default_epi_recipe_blueprint)
144146
export(new_epi_recipe_blueprint)
145147
export(pivot_quantiles)
146148
export(prep)
147-
export(print_frosting)
148-
export(print_preprocessor_recipe)
149149
export(quantile_reg)
150150
export(remove_frosting)
151151
export(slather)

R/epi_recipe.R

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,63 @@ kill_levels <- function(x, keys) {
399399
}
400400

401401
#' @export
402+
print.epi_recipe <- function(x, form_width = 30, ...) {
403+
cli::cli_div(theme = list(.pkg = list("vec-trunc" = Inf, "vec-last" = ", ")))
404+
405+
cli::cli_h1("Recipe")
406+
cli::cli_h3("Inputs")
407+
408+
tab <- table(x$var_info$role, useNA = "ifany")
409+
tab <- stats::setNames(tab, names(tab))
410+
names(tab)[is.na(names(tab))] <- "undeclared role"
411+
412+
roles <- c("outcome", "predictor", "case_weights", "undeclared role")
413+
414+
tab <- c(
415+
tab[names(tab) == roles[1]],
416+
tab[names(tab) == roles[2]],
417+
tab[names(tab) == roles[3]],
418+
sort(tab[!names(tab) %in% roles], TRUE),
419+
tab[names(tab) == roles[4]]
420+
)
421+
422+
cli::cli_text("Number of variables by role")
423+
424+
spaces_needed <- max(nchar(names(tab))) - nchar(names(tab)) +
425+
max(nchar(tab)) - nchar(tab)
426+
427+
cli::cli_verbatim(
428+
glue::glue("{names(tab)}: {strrep('\ua0', spaces_needed)}{tab}")
429+
)
430+
431+
if ("tr_info" %in% names(x)) {
432+
cli::cli_h3("Training information")
433+
nmiss <- x$tr_info$nrows - x$tr_info$ncomplete
434+
nrows <- x$tr_info$nrows
435+
436+
cli::cli_text(
437+
"Training data contained {nrows} data points and {cli::no(nmiss)} \\
438+
incomplete row{?s}."
439+
)
440+
}
441+
442+
if (!is.null(x$steps)) {
443+
cli::cli_h3("Operations")
444+
}
445+
446+
i = 1
447+
for (step in x$steps) {
448+
cat(paste0(i, ". "))
449+
print(step, form_width = form_width)
450+
i = i + 1
451+
}
452+
cli::cli_end()
453+
454+
invisible(x)
455+
}
456+
402457
# Currently only used in the workflow printing
403-
print_preprocessor_recipe <- function (x) {
458+
print_preprocessor_recipe <- function(x, ...) {
404459

405460
recipe <- workflows::extract_preprocessor(x)
406461
steps <- recipe$steps
@@ -421,7 +476,7 @@ print_preprocessor_recipe <- function (x) {
421476
step_names <- map_chr(steps, workflows:::pull_step_name)
422477

423478
if (n_steps <= 10L) {
424-
cli:::cli_ol(step_names)
479+
cli::cli_ol(step_names)
425480
return(invisible(x))
426481
}
427482

R/frosting.R

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,23 @@ 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")
277+
278+
if (!is.null(x$layers)) cli::cli_h3("Layers")
279+
i = 1
280+
for (layer in x$layers){
281+
cat(paste0(i, ". "))
282+
print(layer, form_width = form_width)
283+
i = i + 1
284+
}
285+
cli::cli_end()
286+
invisible(x)
287+
}
288+
272289
# Currently only used in the workflow printing
273290
print_frosting <- function(x, ...) {
274291

@@ -285,7 +302,7 @@ print_frosting <- function(x, ...) {
285302
layer_names <- map_chr(layers, pull_layer_name)
286303

287304
if (n_layers <= 10L) {
288-
cli:::cli_ol(layer_names)
305+
cli::cli_ol(layer_names)
289306
return(invisible(x))
290307
}
291308

R/print_epi_step.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ print_epi_step <- function(
4242
)
4343
more_dots <- ifelse(first_line == length(elements), "", ", ...")
4444
cli::cli_bullets(
45-
c(`*` = "\n {title}: \\\n {.pkg {cli::cli_vec(elements[seq_len(first_line)])}}\\\n {more_dots} \\\n {conjunction} \\\n {.pkg {extra_text}} \\\n {vline_seperator} \\\n {.emph {trained_text}}\\\n {comma_seperator} \\\n {.emph {case_weights_text}}\n "))
45+
c("\n {title}: \\\n {.pkg {cli::cli_vec(elements[seq_len(first_line)])}}\\\n {more_dots} \\\n {conjunction} \\\n {.pkg {extra_text}} \\\n {vline_seperator} \\\n {.emph {trained_text}}\\\n {comma_seperator} \\\n {.emph {case_weights_text}}\n "))
4646
cli::cli_end(theme_div_id)
4747
invisible(NULL)
4848
}

R/print_layer.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ print_layer <- function(
2424
)
2525
more_dots <- ifelse(first_line == length(elements), "", ", ...")
2626
cli::cli_bullets(
27-
c(`*` = "\n {title}: \\\n {.pkg {elements[seq_len(first_line)]}}\\\n {more_dots} \\\n {conjunction} \\\n {.pkg {extra_text}}"))
27+
c("\n {title}: \\\n {.pkg {elements[seq_len(first_line)]}}\\\n {more_dots} \\\n {conjunction} \\\n {.pkg {extra_text}}"))
2828
invisible(NULL)
2929
}

0 commit comments

Comments
 (0)