Skip to content

Commit 46197c8

Browse files
committed
better printing
1 parent 31d5149 commit 46197c8

File tree

2 files changed

+37
-23
lines changed

2 files changed

+37
-23
lines changed

R/misc.R

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,39 @@ check_empty_ellipse <- function (...) {
2828

2929
all_modes <- c("classification", "regression")
3030

31+
model_printer <- function(x, ...) {
32+
non_null_args <- x$args[!vapply(x$args, null_value, lgl(1))]
33+
if (length(non_null_args) > 0) {
34+
cat("Main Arguments:\n")
35+
non_null_args <- lapply(non_null_args, as.character)
36+
non_null_args <- lapply(non_null_args, function(x)
37+
paste0(" ", x[-1], "\n"))
38+
anms <- names(non_null_args)
39+
non_null_args <- paste(anms, unlist(non_null_args), sep = ": ")
40+
cat(non_null_args, sep = "", "\n")
41+
}
42+
if (length(x$others) > 0) {
43+
cat("Engine-Specific Arguments:\n")
44+
others <- lapply(x$others, function(x) paste(deparse(x), sep = "\n", collapse = "\n"))
45+
others <- lapply(others, function(x)
46+
paste0(" ", x, "\n"))
47+
onms <- names(others)
48+
others <- paste(onms, unlist(others), sep = ": ")
49+
cat(others, sep = "", "\n\n")
50+
}
51+
if (!is.null(x$engine)) {
52+
cat("Computational engine:", x$engine, "\n\n")
53+
if (!is.null(x$method$fit)) {
54+
cat("Fit function:\n")
55+
print(x$method$fit)
56+
if (length(x$method$library) > 0) {
57+
if (length(x$method$library) > 1)
58+
cat("\nRequired packages:\n")
59+
else
60+
cat("\nRequired package: ")
61+
cat(paste0(x$method$library, collapse = ", "), "\n")
62+
}
63+
}
64+
}
65+
cat("\n")
66+
}

R/rand_forest.R

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,29 +94,7 @@ rand_forest.default <-
9494
#' @export
9595
print.rand_forest <- function(x, ...) {
9696
cat("Random Forest Model Specification (", x$mode, ")\n\n", sep = "")
97-
non_null_args <- x$args[!vapply(x$args, null_value, lgl(1))]
98-
if (length(non_null_args) > 0) {
99-
cat("Main Arguments:\n")
100-
non_null_args <- lapply(non_null_args, as.character)
101-
non_null_args <- lapply(non_null_args, function(x)
102-
paste0(" ", x[-1], "\n"))
103-
anms <- names(non_null_args)
104-
non_null_args <- paste(anms, unlist(non_null_args), sep = ": ")
105-
cat(non_null_args, sep = "", "\n\n")
106-
}
107-
if (length(x$others) > 0) {
108-
cat("Engine-Specific Arguments:\n")
109-
others <- lapply(x$others, function(x) paste(deparse(x), sep = "\n", collapse = "\n"))
110-
others <- lapply(others, function(x)
111-
paste0(" ", x, "\n"))
112-
onms <- names(others)
113-
others <- paste(onms, unlist(others), sep = ": ")
114-
cat(others, sep = "", "\n\n")
115-
}
116-
if(!is.null(x$engine)) {
117-
cat("Computational engine:", x$engine, "\n\n")
118-
}
119-
97+
model_printer(x, ...)
12098
invisible(x)
12199
}
122100

0 commit comments

Comments
 (0)