Skip to content

Commit 8ccf1be

Browse files
authored
deprecate rpart_train() (#1048)
1 parent 7c40966 commit 8ccf1be

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# parsnip (development version)
22

3+
* `rpart_train()` has been deprecated in favor of using `decision_tree()` with the `"rpart"` engine or `rpart::rpart()` directly (#1044).
4+
35
* Fixed bug in fitting some model types with the `"spark"` engine (#1045).
46

57
* Fixed issues in metadata for the `"brulee"` engine where several arguments were mistakenly protected. (#1050, #1054)

R/decision_tree.R

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,12 @@ check_args.decision_tree <- function(object) {
138138

139139
#' Decision trees via rpart
140140
#'
141-
#' `rpart_train` is a wrapper for `rpart()` tree-based models
141+
#' @description
142+
#' `rpart_train()` is a wrapper for `rpart()` tree-based models
142143
#' where all of the model arguments are in the main function.
143144
#'
145+
#' The function is now deprecated, as parsnip uses `rpart::rpart()` directly.
146+
#'
144147
#' @param formula A model formula.
145148
#' @param data A data frame.
146149
#' @param cp A non-negative number for complexity parameter. Any split
@@ -166,6 +169,12 @@ check_args.decision_tree <- function(object) {
166169
#' @export
167170
rpart_train <-
168171
function(formula, data, weights = NULL, cp = 0.01, minsplit = 20, maxdepth = 30, ...) {
172+
lifecycle::deprecate_warn(
173+
"1.2.0",
174+
"rpart_train()",
175+
details = 'Instead, use `decision_tree(engine = "rpart")` or `rpart::rpart()` directly.'
176+
)
177+
169178
bitness <- 8 * .Machine$sizeof.pointer
170179
if (bitness == 32 & maxdepth > 30)
171180
maxdepth <- 30

tests/testthat/test_decision_tree.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ test_that('bad input', {
2626
expect_snapshot_error(translate(decision_tree(formula = y ~ x)))
2727
})
2828

29+
test_that('rpart_train is stop-deprecated when it ought to be (#1044)', {
30+
skip_on_cran()
31+
32+
# once this test fails, transition `rpart_train()` to `deprecate_stop()`
33+
# and transition this test to fail if `rpart_train()` still exists after a year.
34+
if (Sys.Date() > "2025-01-01") {
35+
expect_error(rpart_train(mpg ~ ., mtcars))
36+
}
37+
})
38+
2939
# ------------------------------------------------------------------------------
3040

3141
test_that('argument checks for data dimensions', {

0 commit comments

Comments
 (0)