Skip to content

Commit

Permalink
New print method for R6 class
Browse files Browse the repository at this point in the history
  • Loading branch information
jpfitzinger committed Sep 15, 2022
1 parent 4a3c4ea commit f01e609
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions R/model_definition.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#' @importFrom crayon bold italic red green yellow


# R6 class for model object
model_definition <- R6::R6Class(
"tidyFit",
public = list(
Expand Down Expand Up @@ -43,7 +44,14 @@ model_definition <- R6::R6Class(
)
do.call(.coef, all_args)
},
print = function(...) print(paste0("<", self$method, "> object (", ifelse(is.null(self$object), "not fitted", "fitted"), ")")),
print = function(...) {
cat("<tidyFit> object\n", crayon::italic("method:"),
crayon::bold(self$method), "|",
crayon::italic("mode:"), crayon::bold(self$mode), "|",
crayon::italic("fitted:"), crayon::bold(ifelse(is.null(self$object), "no", "yes")), "\n",
ifelse(is.null(self$error), crayon::green("no errors ✔"), crayon::red("check errors ✖")), "|",
ifelse(is.null(self$warnings), crayon::green("no warnings ✔"), crayon::yellow("check warnings ✖")))
},
set_args = function(..., overwrite = TRUE) {
new_args <- lapply(list(...), unlist)
if (overwrite) {
Expand All @@ -65,6 +73,7 @@ model_definition <- R6::R6Class(
)
)

# Capture errors, warnings and messages from purrr safely/quietly function
.store_on_self <- function(self, model) {
self$object <- model$result$result
self$error <- model$error[[1]]
Expand Down

0 comments on commit f01e609

Please sign in to comment.