Skip to content

Commit 8f278ef

Browse files
committed
S3 control method for #128
1 parent b503bec commit 8f278ef

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

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 mode\n")
34+
if (x$catch > 1)
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)