Skip to content

Commit a2ec841

Browse files
test interactions with butcher (#28)
* bundle both fitted and original recipe see `workflows::extract_recipe.workflow` definition for locations. the workflows bundler tripped up at predict time with a trained recipe because only the recipe _specification_ had been effectively bundled * test interaction with butcher * add butcher to Suggests * test butcher interaction conditionally * add roxygen template on butcher and bundle * Add link, tiny edits * Redocument Co-authored-by: Julia Silge <[email protected]>
1 parent 1c03b5f commit a2ec841

18 files changed

+323
-16
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Imports:
3030
utils
3131
Suggests:
3232
bonsai,
33+
butcher,
3334
caret,
3435
callr,
3536
covr,

R/bundle_caret.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#' @details Primarily, these methods call [bundle()] on the output of
1313
#' `train_model_object$finalModel`. See the class of the output of that
1414
#' slot for more details on the bundling method for that object.
15+
#' @template butcher_details
1516
#' @examplesIf rlang::is_installed("caret")
1617
#' # fit model and bundle ------------------------------------------------
1718
#' library(caret)

R/bundle_embed.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#' from [embed][embed::step_umap].
1111
#' @template param_unused_dots
1212
#' @seealso This method wraps [uwot::save_uwot()] and [uwot::load_uwot()].
13+
#' @template butcher_details
1314
#' @examplesIf rlang::is_installed("recipes") && rlang::is_installed("embed")
1415
#' # fit model and bundle ------------------------------------------------
1516
#' library(recipes)

R/bundle_parsnip.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#' @details Primarily, these methods call [bundle()] on the output of
1313
#' [parsnip::extract_fit_engine()]. See the class of the output of that
1414
#' function for more details on the bundling method for that object.
15+
#' @template butcher_details
1516
#' @examplesIf rlang::is_installed("parsnip") && rlang::is_installed("xgboost")
1617
#' # fit model and bundle ------------------------------------------------
1718
#' library(parsnip)

R/bundle_workflows.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#'
1313
#' @details This bundler wraps [bundle.model_fit()] and [bundle.recipe()].
1414
#'
15+
#' @template butcher_details
16+
#'
1517
#' @examplesIf rlang::is_installed(c("workflows", "parsnip", "recipes", "xgboost"))
1618
#' # fit model and bundle ------------------------------------------------
1719
#' library(workflows)
@@ -50,12 +52,14 @@ bundle.workflow <- function(x, ...) {
5052

5153
res <- swap_element(x, "fit", "fit")
5254
res <- swap_element(res, "pre", "actions", "recipe", "recipe")
55+
res <- swap_element(res, "pre", "mold", "blueprint", "recipe")
5356

5457
bundle_constr(
5558
object = res,
5659
situate = situate_constr(function(object) {
5760
res <- bundle::swap_element(object, "fit", "fit")
5861
res <- bundle::swap_element(res, "pre", "actions", "recipe", "recipe")
62+
res <- bundle::swap_element(res, "pre", "mold", "blueprint", "recipe")
5963

6064
structure(res, class = !!class(x))
6165
}),

R/bundle_xgboost.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#' @seealso This method adapts the xgboost internal functions
1414
#' `predict.xgb.Booster.handle()` and `xgb.handleToBooster()`, as well
1515
#' as [xgboost::xgb.serialize()].
16+
#' @template butcher_details
1617
#' @examplesIf rlang::is_installed("xgboost")
1718
#' # fit model and bundle ------------------------------------------------
1819
#' library(xgboost)

man-roxygen/butcher_details.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#' @section bundle and butcher:
2+
#' The [butcher](https://butcher.tidymodels.org/) package allows you to remove
3+
#' parts of a fitted model object that are not needed for prediction.
4+
#'
5+
#' This bundle method is compatible with pre-butchering. That is, for a
6+
#' fitted model `x`, you can safely call:
7+
#'
8+
#' ```
9+
#' res <-
10+
#' x %>%
11+
#' butcher() %>%
12+
#' bundle()
13+
#' ```
14+
#'
15+
#' and predict with the output of `unbundle(res)` in a new R session.
16+
#'
17+
#' @md

man/bundle_caret.Rd

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

man/bundle_embed.Rd

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

man/bundle_parsnip.Rd

Lines changed: 17 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)