Skip to content

Commit 5f746aa

Browse files
authored
Merge pull request #155 from tidymodels/S3-control
S3 control objects to close #128
2 parents b503bec + 6b79d98 commit 5f746aa

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ S3method(predict_raw,"_multnet")
3232
S3method(predict_raw,model_fit)
3333
S3method(print,boost_tree)
3434
S3method(print,decision_tree)
35+
S3method(print,fit_control)
3536
S3method(print,linear_reg)
3637
S3method(print,logistic_reg)
3738
S3method(print,mars)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
of possible varying arguments is returned (as opposed to only the arguments
1212
that are actually varying).
1313

14+
* `fit_control()` not returns an S3 method.
15+
1416
## Bug Fixes
1517

1618
* `varying_args()` now uses the version from the `generics` package. This means

R/fit_control.R

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#' Control the fit function
2-
#'
3-
#' Options can be passed to the [fit()] function that control the output and
2+
#'
3+
#' Options can be passed to the [fit()] function that control the output and
44
#' computations
5-
#'
5+
#'
66
#' @param verbosity An integer where a value of zero indicates
77
#' that no messages or output should be shown when packages are
88
#' loaded or when the model is fit. A value of 1 means that package
@@ -14,12 +14,24 @@
1414
#' the model inside of `try(, silent = TRUE)`. If the model fails,
1515
#' an object is still returned (without an error) that inherits the
1616
#' class "try-error".
17-
#' @return A named list with the results of the function call
17+
#' @return An S3 object with class "fit_control" that is a named list with the
18+
#' results of the function call
1819
#' @export
19-
#'
20+
#'
2021

2122
fit_control <- function(verbosity = 1L, catch = FALSE) {
2223
res <- list(verbosity = verbosity, catch = catch)
2324
res <- check_control(res)
25+
class(res) <- "fit_control"
2426
res
2527
}
28+
29+
#' @export
30+
print.fit_control <- function(x, ...) {
31+
cat("parsnip control object\n")
32+
if (x$verbosity > 1)
33+
cat(" - verbose level", x$verbosity, "\n")
34+
if (x$catch)
35+
cat(" - fit errors will be caught\n")
36+
invisible(x)
37+
}

man/fit_control.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)