Skip to content

Should there be a helper function for print methods #567

Closed
@EmilHvitfeldt

Description

@EmilHvitfeldt

All the print methods follow this pattern

parsnip/R/boost_tree.R

Lines 86 to 95 in af46f57

print.boost_tree <- function(x, ...) {
cat("Boosted Tree Model Specification (", x$mode, ")\n\n", sep = "")
model_printer(x, ...)
if (!is.null(x$method$fit$args)) {
cat("Model fit template:\n")
print(show_call(x))
}
invisible(x)
}

What about we create a wrapper so we can do

print_helper <- function(name, x, ...) {
  cat(name, " Specification (", x$mode, ")\n\n", sep = "")
  model_printer(x, ...)
  
  if (!is.null(x$method$fit$args)) {
    cat("Model fit template:\n")
    print(show_call(x))
  }
  invisible(x)
}

print.decision_tree <- function(x, ...) {
  print_helper("Decision Tree Model", x, ...)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    upkeepmaintenance, infrastructure, and similar

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions