From 5866aeaf5db65464fb13163a4b4e76db78a12992 Mon Sep 17 00:00:00 2001 From: simonpcouch Date: Tue, 16 Jan 2024 09:03:22 -0600 Subject: [PATCH] deprecate `rpart_train()` --- NEWS.md | 2 ++ R/decision_tree.R | 11 ++++++++++- tests/testthat/test_decision_tree.R | 10 ++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index cbd470039..e3a1b0cfc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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). + * `.filter_eval_time()` was moved to the survival standalone file. * Improved errors and documentation related to special terms in formulas. See `?model_formula` to learn more. (#770, #1014) diff --git a/R/decision_tree.R b/R/decision_tree.R index e234e43de..698a6512e 100644 --- a/R/decision_tree.R +++ b/R/decision_tree.R @@ -137,9 +137,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 @@ -165,6 +168,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( + "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 diff --git a/tests/testthat/test_decision_tree.R b/tests/testthat/test_decision_tree.R index adc688435..bb1391299 100644 --- a/tests/testthat/test_decision_tree.R +++ b/tests/testthat/test_decision_tree.R @@ -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', {