Skip to content

Commit 2e17818

Browse files
authored
move forward with deprecation of req_pkgs() (#915)
1 parent bb3331c commit 2e17818

File tree

6 files changed

+31
-57
lines changed

6 files changed

+31
-57
lines changed

NAMESPACE

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ S3method(print,control_parsnip)
6161
S3method(print,model_fit)
6262
S3method(print,model_spec)
6363
S3method(print,nullmodel)
64-
S3method(req_pkgs,model_fit)
65-
S3method(req_pkgs,model_spec)
6664
S3method(required_pkgs,model_fit)
6765
S3method(required_pkgs,model_spec)
6866
S3method(set_args,default)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* glmnet models fitted with base-R family objects are now supported for `linear_reg()`, `logistic_reg()`, and `multinomial_reg()` (#890).
44

5+
* Moved forward with the deprecation of `req_pkgs()` in favor of `required_pkgs()`. The function will now error (#871).
6+
57
* Made `fit()` behave consistently with respect to missingness in the classification setting. Previously, `fit()` erroneously raised an error about the class of the outcome when there were no complete cases, and now always passes along complete cases to be handled by the modeling function (#888).
68

79
* Fixed bug where model fits with factor predictors and `engine = "kknn"` would fail when the package's namespace hadn't been attached (#264).

R/req_pkgs.R

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,9 @@
77
#' @param ... Not used.
88
#' @return A character string of package names (if any).
99
#' @details
10-
#' For a model specification, the engine must be set. The list produced by
11-
#' `req_pkgs()`does not include the `parsnip` package while `required_pkgs()`
12-
#' does.
13-
#' @examples
14-
#' should_fail <- try(req_pkgs(linear_reg()), silent = TRUE)
15-
#' should_fail
10+
#' This function has been deprecated in favor of `required_pkgs()`.
1611
#'
17-
#' linear_reg() %>%
18-
#' set_engine("glmnet") %>%
19-
#' req_pkgs()
20-
#'
21-
#' linear_reg() %>%
22-
#' set_engine("lm") %>%
23-
#' fit(mpg ~ ., data = mtcars) %>%
24-
#' req_pkgs()
2512
#' @export
2613
req_pkgs <- function(x, ...) {
27-
lifecycle::deprecate_soft("0.1.8", "req_pkgs()", "required_pkgs()")
28-
UseMethod("req_pkgs")
29-
}
30-
31-
#' @export
32-
#' @rdname req_pkgs
33-
req_pkgs.model_spec <- function(x, ...) {
34-
if (is.null(x$engine)) {
35-
rlang::abort("Please set an engine.")
36-
}
37-
setdiff(get_pkgs(x, FALSE), "parsnip")
38-
}
39-
40-
#' @export
41-
#' @rdname req_pkgs
42-
req_pkgs.model_fit <- function(x, ...) {
43-
setdiff(get_pkgs(x$spec, FALSE), "parsnip")
14+
lifecycle::deprecate_stop("0.1.8", "req_pkgs()", "required_pkgs()")
4415
}

man/req_pkgs.Rd

Lines changed: 1 addition & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/packages.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# required packages
2+
3+
Code
4+
expect_equal(req_pkgs(glmn), "glmnet")
5+
Condition
6+
Error:
7+
! `req_pkgs()` was deprecated in parsnip 0.1.8 and is now defunct.
8+
i Please use `required_pkgs()` instead.
9+
10+
---
11+
12+
Code
13+
expect_equal(req_pkgs(lm_fit), "stats")
14+
Condition
15+
Error:
16+
! `req_pkgs()` was deprecated in parsnip 0.1.8 and is now defunct.
17+
i Please use `required_pkgs()` instead.
18+

tests/testthat/test_packages.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,24 @@ test_that('required packages', {
99
glmn <-
1010
linear_reg() %>%
1111
set_engine("glmnet")
12-
expect_equal(req_pkgs(glmn), "glmnet")
1312
expect_equal(required_pkgs(glmn), c("parsnip", "glmnet"))
1413
expect_equal(required_pkgs(glmn, infra = FALSE), c("glmnet"))
1514

15+
expect_snapshot(error = TRUE, {
16+
expect_equal(req_pkgs(glmn), "glmnet")
17+
})
1618

1719
lm_fit <-
1820
linear_reg() %>%
1921
set_engine("lm") %>%
2022
fit(mpg ~ ., data = mtcars)
21-
expect_equal(req_pkgs(lm_fit), "stats")
23+
2224
expect_equal(required_pkgs(lm_fit), c("parsnip", "stats"))
2325
expect_equal(required_pkgs(lm_fit, infra = FALSE), c("stats"))
26+
27+
expect_snapshot(error = TRUE, {
28+
expect_equal(req_pkgs(lm_fit), "stats")
29+
})
2430
})
2531

2632
# ------------------------------------------------------------------------------

0 commit comments

Comments
 (0)