Skip to content

Commit 97e8d2b

Browse files
add tidy() method for model_fit objects
1 parent 9b28f37 commit 97e8d2b

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

DESCRIPTION

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Imports:
2929
tidyr,
3030
globals
3131
Roxygen: list(markdown = TRUE)
32-
RoxygenNote: 6.1.0.9000
32+
RoxygenNote: 6.1.1
3333
Suggests:
3434
testthat,
3535
knitr,
@@ -39,4 +39,3 @@ Suggests:
3939
xgboost,
4040
covr,
4141
sparklyr
42-

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export(show_call)
119119
export(surv_reg)
120120
export(svm_poly)
121121
export(svm_rbf)
122+
export(tidy.model_fit)
122123
export(translate)
123124
export(varying)
124125
export(varying_args)

R/tidy.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#' Turn a parsnip model object into a tidy tibble
2+
#'
3+
#' This method tidies the model in a parsnip model object, if it exists.
4+
#'
5+
#' @inheritParams generics::tidy
6+
#'
7+
#' @return a tibble
8+
#' @export
9+
#'
10+
#' @examples
11+
#' logistic_reg() %>%
12+
#' set_engine("glm") %>%
13+
#' fit(Class ~ funded_amnt + int_rate, data = lending_club) %>%
14+
#' # tidying model object and passing arguments to broom:::tidy.glm
15+
#' tidy(conf.int = TRUE, exponentiate = TRUE)
16+
tidy.model_fit <- function(x, ...) {
17+
tryCatch(generics::tidy(x$fit, ...),
18+
error = function(error) {
19+
cat("Error:", error$message)
20+
}
21+
)
22+
}

man/tidy.model_fit.Rd

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)