Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ export(rand_forest)
export(repair_call)
export(req_pkgs)
export(required_pkgs)
export(rpart_train)
export(rule_fit)
export(set_args)
export(set_dependency)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

* Aligned `null_model()` with other model types; the model type now has an engine argument that defaults to `"parsnip"` and is checked with the same machinery that checks other model types in the package (#1083).

* The deprecated function `rpart_train()` was removed after its deprecation period (#1044).

## Bug Fixes

* Make sure that parsnip does not convert ordered factor predictions to be unordered.
Expand Down
73 changes: 0 additions & 73 deletions R/decision_tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,76 +129,3 @@ translate.decision_tree <- function(x, engine = x$engine, ...) {
check_args.decision_tree <- function(object, call = rlang::caller_env()) {
invisible(object)
}

# ------------------------------------------------------------------------------

#' Decision trees via rpart
#'
#' @description
#' `rpart_train()` is a wrapper for `rpart()` tree-based models
#' where all of the model arguments are in the main function.
#'
#' The function is now deprecated, as parsnip uses `rpart::rpart()` directly.
#'
#' @param formula A model formula.
#' @param data A data frame.
#' @param cp A non-negative number for complexity parameter. Any split
#' that does not decrease the overall lack of fit by a factor of
#' `cp` is not attempted. For instance, with anova splitting,
#' this means that the overall R-squared must increase by `cp` at
#' each step. The main role of this parameter is to save computing
#' time by pruning off splits that are obviously not worthwhile.
#' Essentially, the user informs the program that any split which
#' does not improve the fit by `cp` will likely be pruned off by
#' cross-validation, and that hence the program need not pursue it.
#' @param weights Optional case weights.
#' @param minsplit An integer for the minimum number of observations
#' that must exist in a node in order for a split to be attempted.
#' @param maxdepth An integer for the maximum depth of any node
#' of the final tree, with the root node counted as depth 0.
#' Values greater than 30 `rpart` will give nonsense results on
#' 32-bit machines. This function will truncate `maxdepth` to 30 in
#' those cases.
#' @param ... Other arguments to pass to either `rpart` or `rpart.control`.
#' @return A fitted rpart model.
#' @keywords internal
#' @export
rpart_train <-
function(formula, data, weights = NULL, cp = 0.01, minsplit = 20, maxdepth = 30, ...) {
lifecycle::deprecate_warn(
"1.2.0",
"rpart_train()",
details = 'Instead, use `decision_tree(engine = "rpart")` or `rpart::rpart()` directly.'
)

bitness <- 8 * .Machine$sizeof.pointer
if (bitness == 32 & maxdepth > 30)
maxdepth <- 30

other_args <- list(...)
protect_ctrl <- c("minsplit", "maxdepth", "cp")
protect_fit <- NULL
f_names <- names(formals(getFromNamespace("rpart", "rpart")))
c_names <- names(formals(getFromNamespace("rpart.control", "rpart")))
other_args <- other_args[!(other_args %in% c(protect_ctrl, protect_fit))]
ctrl_args <- other_args[names(other_args) %in% c_names]
fit_args <- other_args[names(other_args) %in% f_names]

ctrl <- call2("rpart.control", .ns = "rpart")
ctrl$minsplit <- minsplit
ctrl$maxdepth <- maxdepth
ctrl$cp <- cp
ctrl <- rlang::call_modify(ctrl, !!!ctrl_args)

fit_call <- call2("rpart", .ns = "rpart")
fit_call$formula <- expr(formula)
fit_call$data <- expr(data)
fit_call$control <- ctrl
if (!is.null(weights)) {
fit_call$weights <- quote(weights)
}
fit_call <- rlang::call_modify(fit_call, !!!fit_args)

eval_tidy(fit_call)
}

2 changes: 1 addition & 1 deletion R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@
}

if (inherits(x, "workflow")) {
x <- x %>% extract_fit_parsnip(x)
x <- x %>% hardhat::extract_fit_parsnip(x)

Check warning on line 605 in R/misc.R

View check run for this annotation

Codecov / codecov/patch

R/misc.R#L605

Added line #L605 was not covered by tests
}
model_spec <- extract_spec_parsnip(x)
model_engine <- model_spec$engine
Expand Down
4 changes: 2 additions & 2 deletions man/dot-get_prediction_column_names.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 0 additions & 54 deletions man/rpart_train.Rd

This file was deleted.

10 changes: 0 additions & 10 deletions tests/testthat/test-decision_tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ test_that('bad input', {
)
})

test_that('rpart_train is stop-deprecated when it ought to be (#1044)', {
skip_on_cran()

# once this test fails, transition `rpart_train()` to `deprecate_stop()`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trigger

# and transition this test to fail if `rpart_train()` still exists after a year.
if (Sys.Date() > "2025-01-01") {
expect_snapshot(error = TRUE, rpart_train(mpg ~ ., mtcars))
}
})

# ------------------------------------------------------------------------------

test_that('argument checks for data dimensions', {
Expand Down
Loading