From 8ccf1be367daab2cc21a343b222e8ce417ba9be7 Mon Sep 17 00:00:00 2001 From: "Simon P. Couch" Date: Thu, 25 Jan 2024 11:59:38 -0600 Subject: [PATCH] deprecate `rpart_train()` (#1048) --- 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 d1a07b169..166330ff1 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). + * Fixed bug in fitting some model types with the `"spark"` engine (#1045). * Fixed issues in metadata for the `"brulee"` engine where several arguments were mistakenly protected. (#1050, #1054) diff --git a/R/decision_tree.R b/R/decision_tree.R index b0e7741c0..98c13d26a 100644 --- a/R/decision_tree.R +++ b/R/decision_tree.R @@ -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 @@ -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( + "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', {