Skip to content

Commit 4473786

Browse files
simonpcouchtopepo
andauthored
refactor model specification printing (#739)
* add model printing helper * delete redundant model print methods note that the only changes needed to pass existing tests is 4 snapshot updates, where `"Model "` is added preceding `"Specification"` in the header. * delete old model spec printing tests * add new model spec printing tests * add `NEWS` entry * move print helpers and methods to new `R/print.R` file * re`document()` * add null model description * test fixes re: upstream merge Co-authored-by: Max Kuhn <mxkuhn@gmail.com>
1 parent 9b4c0b8 commit 4473786

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+264
-492
lines changed

NAMESPACE

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,39 +49,10 @@ S3method(predict_raw,"_multnet")
4949
S3method(predict_raw,model_fit)
5050
S3method(predict_survival,model_fit)
5151
S3method(predict_time,model_fit)
52-
S3method(print,C5_rules)
53-
S3method(print,bag_mars)
54-
S3method(print,bag_tree)
55-
S3method(print,bart)
56-
S3method(print,boost_tree)
5752
S3method(print,control_parsnip)
58-
S3method(print,cubist_rules)
59-
S3method(print,decision_tree)
60-
S3method(print,discrim_flexible)
61-
S3method(print,discrim_linear)
62-
S3method(print,discrim_quad)
63-
S3method(print,discrim_regularized)
64-
S3method(print,gen_additive_mod)
65-
S3method(print,linear_reg)
66-
S3method(print,logistic_reg)
67-
S3method(print,mars)
68-
S3method(print,mlp)
6953
S3method(print,model_fit)
7054
S3method(print,model_spec)
71-
S3method(print,multinom_reg)
72-
S3method(print,naive_Bayes)
73-
S3method(print,nearest_neighbor)
7455
S3method(print,nullmodel)
75-
S3method(print,pls)
76-
S3method(print,poisson_reg)
77-
S3method(print,proportional_hazards)
78-
S3method(print,rand_forest)
79-
S3method(print,rule_fit)
80-
S3method(print,surv_reg)
81-
S3method(print,survival_reg)
82-
S3method(print,svm_linear)
83-
S3method(print,svm_poly)
84-
S3method(print,svm_rbf)
8556
S3method(req_pkgs,model_fit)
8657
S3method(req_pkgs,model_spec)
8758
S3method(required_pkgs,model_fit)
@@ -267,6 +238,7 @@ export(predict_survival.model_fit)
267238
export(predict_time)
268239
export(predict_time.model_fit)
269240
export(prepare_data)
241+
export(print_model_spec)
270242
export(proportional_hazards)
271243
export(rand_forest)
272244
export(repair_call)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
* Model type functions will now message informatively if a needed parsnip extension package is not loaded (#731).
2525

26+
* Refactored internals of model specification printing functions. These changes are non-breaking for extension packages, but the new `print_model_spec()` helper is exported for use in extensions if desired (#739).
27+
2628

2729
# parsnip 0.2.1
2830

R/bag_mars.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,6 @@ bag_mars <-
4242
)
4343
}
4444

45-
#' @export
46-
print.bag_mars <- function(x, ...) {
47-
cat("Bagged MARS Model Specification (", x$mode, ")\n\n", sep = "")
48-
model_printer(x, ...)
49-
50-
if (is_printable_spec(x)) {
51-
cat("Model fit template:\n")
52-
print(show_call(x))
53-
}
54-
invisible(x)
55-
}
56-
5745
# ------------------------------------------------------------------------------
5846

5947
#' @method update bag_mars

R/bag_tree.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,6 @@ bag_tree <-
4646
)
4747
}
4848

49-
#' @export
50-
print.bag_tree <- function(x, ...) {
51-
cat("Bagged Decision Tree Model Specification (", x$mode, ")\n\n", sep = "")
52-
model_printer(x, ...)
53-
54-
if (is_printable_spec(x)) {
55-
cat("Model fit template:\n")
56-
print(show_call(x))
57-
}
58-
invisible(x)
59-
}
60-
6149
# ------------------------------------------------------------------------------
6250

6351
#' @method update bag_tree

R/bart.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,6 @@ bart <-
9090
)
9191
}
9292

93-
#' @export
94-
print.bart <- function(x, ...) {
95-
cat("BART Model Specification (", x$mode, ")\n\n", sep = "")
96-
model_printer(x, ...)
97-
98-
if (is_printable_spec(x)) {
99-
cat("Model fit template:\n")
100-
print(show_call(x))
101-
}
102-
invisible(x)
103-
}
104-
10593
# ------------------------------------------------------------------------------
10694

10795
#' @method update bart

R/boost_tree.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,6 @@ boost_tree <-
8080
)
8181
}
8282

83-
#' @export
84-
print.boost_tree <- function(x, ...) {
85-
cat("Boosted Tree Model Specification (", x$mode, ")\n\n", sep = "")
86-
model_printer(x, ...)
87-
88-
if (is_printable_spec(x)) {
89-
cat("Model fit template:\n")
90-
print(show_call(x))
91-
}
92-
invisible(x)
93-
}
94-
9583
# ------------------------------------------------------------------------------
9684

9785
#' @method update boost_tree

R/c5_rules.R

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,6 @@ C5_rules <-
6363
)
6464
}
6565

66-
#' @export
67-
print.C5_rules <- function(x, ...) {
68-
cat("C5.0 Model Specification (", x$mode, ")\n\n", sep = "")
69-
model_printer(x, ...)
70-
71-
if (is_printable_spec(x)) {
72-
cat("Model fit template:\n")
73-
print(show_call(x))
74-
}
75-
76-
invisible(x)
77-
}
78-
79-
8066
# ------------------------------------------------------------------------------
8167

8268
#' Updating a model specification

R/cubist_rules.R

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,6 @@ cubist_rules <-
8989
)
9090
}
9191

92-
#' @export
93-
print.cubist_rules <- function(x, ...) {
94-
cat("Cubist Model Specification (", x$mode, ")\n\n", sep = "")
95-
model_printer(x, ...)
96-
97-
if (is_printable_spec(x)) {
98-
cat("Model fit template:\n")
99-
print(show_call(x))
100-
}
101-
102-
invisible(x)
103-
}
104-
105-
10692
# ------------------------------------------------------------------------------
10793

10894
#' @param object A Cubist model specification.

R/decision_tree.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,6 @@ decision_tree <-
5151
)
5252
}
5353

54-
#' @export
55-
print.decision_tree <- function(x, ...) {
56-
cat("Decision Tree Model Specification (", x$mode, ")\n\n", sep = "")
57-
model_printer(x, ...)
58-
59-
if (is_printable_spec(x)) {
60-
cat("Model fit template:\n")
61-
print(show_call(x))
62-
}
63-
invisible(x)
64-
}
65-
6654
# ------------------------------------------------------------------------------
6755

6856
#' @method update decision_tree

R/discrim_flexible.R

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,6 @@ discrim_flexible <-
4545
)
4646
}
4747

48-
#' @export
49-
print.discrim_flexible <- function(x, ...) {
50-
cat("Flexible Discriminant Model Specification (", x$mode, ")\n\n", sep = "")
51-
model_printer(x, ...)
52-
53-
if (is_printable_spec(x)) {
54-
cat("Model fit template:\n")
55-
print(show_call(x))
56-
}
57-
58-
invisible(x)
59-
}
60-
6148
# ------------------------------------------------------------------------------
6249

6350
#' Update a model specification

0 commit comments

Comments
 (0)