Skip to content

deprecate rpart_train() #1048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 25, 2024
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# parsnip (development version)

* `rpart_train()` has been deprecated in favor of using `decision_tree()` with the `"rpart"` engine or `rpart::rpart()` directly (#1044).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some of these bullets have the parens before the periods, others not. We can fix before release.☃️

Copy link
Member

@hfrick hfrick Jan 17, 2024

Choose a reason for hiding this comment

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

The style guide says to put them before the period 👍

Copy link
Member

Choose a reason for hiding this comment

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

I'm so opposed to that part of the style guide 😄


* Fixed bug in fitting some model types with the `"spark"` engine (#1045).

* Fixed issue in `mlp()` metadata where the `stop_iter` engine argument had been mistakenly protected for the `"brulee"` engine. (#1050)
Expand Down
11 changes: 10 additions & 1 deletion R/decision_tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,12 @@ check_args.decision_tree <- function(object) {

#' Decision trees via rpart
#'
#' `rpart_train` is a wrapper for `rpart()` tree-based models
#' @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
Expand All @@ -166,6 +169,12 @@ check_args.decision_tree <- function(object) {
#' @export
rpart_train <-
function(formula, data, weights = NULL, cp = 0.01, minsplit = 20, maxdepth = 30, ...) {
lifecycle::deprecate_warn(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Starting with a more aggressive deprecation as, from what I can tell, rpart_train() was never used, even when it was first committed.

"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
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test_decision_tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ test_that('bad input', {
expect_snapshot_error(translate(decision_tree(formula = y ~ x)))
})

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()`
# and transition this test to fail if `rpart_train()` still exists after a year.
if (Sys.Date() > "2025-01-01") {
expect_error(rpart_train(mpg ~ ., mtcars))
}
})

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

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