Skip to content

Commit

Permalink
cat() rather than raising conditions (closes #229)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch committed Oct 23, 2024
1 parent b9ef734 commit cea7ebe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# stacks (development version)

* Model stack and data stack print methods no longer raise conditions to
print to the console (#228).

* Added missing commas and addressed formatting issues throughout the vignettes and articles. Backticks for package names were removed and missing parentheses for functions were added (@Joscelinrocha, #218).

# stacks 1.0.5
Expand Down
17 changes: 9 additions & 8 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,28 @@ print.data_stack <- function(x, ...) {
#' @export
print.model_stack <- function(x, n = 10, ...) {

rlang::inform(cli::rule("A stacked ensemble model",
cli::cli_text(cli::rule("A stacked ensemble model",
width = min(65, cli::console_width())))

member_summary(x)

print_top_coefs(x)

if (is.null(x[["member_fits"]])) {
rlang::inform("\nMembers have not yet been fitted with `fit_members()`.")
cli::cli_text("\n")
cli::cli_text("Members have not yet been fitted with `fit_members()`.")
}

invisible(NULL)
}

#' @export
print.butchered_linear_stack <- function(x, ...) {
rlang::inform(cli::rule("A stacked ensemble model",
cli::cli_text(cli::rule("A stacked ensemble model",
width = min(65, cli::console_width())))

rlang::inform("\nPrint methods for butchered model stacks are disabled.")
cli::cli_text("\n")
cli::cli_text("Print methods for butchered model stacks are disabled.")
}

top_coefs <- function(x, penalty = x$penalty$penalty, n = 10) {
Expand Down Expand Up @@ -131,10 +133,9 @@ top_coefs <- function(x, penalty = x$penalty$penalty, n = 10) {
print_top_coefs <- function(x, penalty = x$penalty$penalty, n = 10, digits = 3) {
res <- top_coefs(x, penalty = penalty, n = n)

msg <- paste0("\nThe ", nrow(res), " highest weighted member",
if (x$mode == "regression") {"s"} else {" classes"},
" are:")
rlang::inform(msg)
cli::cli_text("\n")
values <- if (x$mode == "regression") {"s"} else {" classes"}
cli::cli_text("The {nrow(res)} highest weighted member{values} are:")
print(res)
invisible(NULL)
}
Expand Down

0 comments on commit cea7ebe

Please sign in to comment.