Skip to content

move forward with deprecation of req_pkgs() #915

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 1 commit into from
Mar 10, 2023
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: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ S3method(print,control_parsnip)
S3method(print,model_fit)
S3method(print,model_spec)
S3method(print,nullmodel)
S3method(req_pkgs,model_fit)
S3method(req_pkgs,model_spec)
S3method(required_pkgs,model_fit)
S3method(required_pkgs,model_spec)
S3method(set_args,default)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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

* Moved forward with the deprecation of `req_pkgs()` in favor of `required_pkgs()`. The function will now error (#871).

* 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).

* `.organize_glmnet_pred()` now expects predictions for a single penalty value (#876).
Expand Down
33 changes: 2 additions & 31 deletions R/req_pkgs.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,9 @@
#' @param ... Not used.
#' @return A character string of package names (if any).
#' @details
#' For a model specification, the engine must be set. The list produced by
#' `req_pkgs()`does not include the `parsnip` package while `required_pkgs()`
#' does.
#' @examples
#' should_fail <- try(req_pkgs(linear_reg()), silent = TRUE)
#' should_fail
#' This function has been deprecated in favor of `required_pkgs()`.
#'
#' linear_reg() %>%
#' set_engine("glmnet") %>%
#' req_pkgs()
#'
#' linear_reg() %>%
#' set_engine("lm") %>%
#' fit(mpg ~ ., data = mtcars) %>%
#' req_pkgs()
#' @export
req_pkgs <- function(x, ...) {
lifecycle::deprecate_soft("0.1.8", "req_pkgs()", "required_pkgs()")
UseMethod("req_pkgs")
}

#' @export
#' @rdname req_pkgs
req_pkgs.model_spec <- function(x, ...) {
if (is.null(x$engine)) {
rlang::abort("Please set an engine.")
}
setdiff(get_pkgs(x, FALSE), "parsnip")
}

#' @export
#' @rdname req_pkgs
req_pkgs.model_fit <- function(x, ...) {
setdiff(get_pkgs(x$spec, FALSE), "parsnip")
lifecycle::deprecate_stop("0.1.8", "req_pkgs()", "required_pkgs()")
}
23 changes: 1 addition & 22 deletions man/req_pkgs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions tests/testthat/_snaps/packages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# required packages

Code
expect_equal(req_pkgs(glmn), "glmnet")
Condition
Error:
! `req_pkgs()` was deprecated in parsnip 0.1.8 and is now defunct.
i Please use `required_pkgs()` instead.

---

Code
expect_equal(req_pkgs(lm_fit), "stats")
Condition
Error:
! `req_pkgs()` was deprecated in parsnip 0.1.8 and is now defunct.
i Please use `required_pkgs()` instead.

10 changes: 8 additions & 2 deletions tests/testthat/test_packages.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@ test_that('required packages', {
glmn <-
linear_reg() %>%
set_engine("glmnet")
expect_equal(req_pkgs(glmn), "glmnet")
expect_equal(required_pkgs(glmn), c("parsnip", "glmnet"))
expect_equal(required_pkgs(glmn, infra = FALSE), c("glmnet"))

expect_snapshot(error = TRUE, {
expect_equal(req_pkgs(glmn), "glmnet")
})

lm_fit <-
linear_reg() %>%
set_engine("lm") %>%
fit(mpg ~ ., data = mtcars)
expect_equal(req_pkgs(lm_fit), "stats")

expect_equal(required_pkgs(lm_fit), c("parsnip", "stats"))
expect_equal(required_pkgs(lm_fit, infra = FALSE), c("stats"))

expect_snapshot(error = TRUE, {
expect_equal(req_pkgs(lm_fit), "stats")
})
})

# ------------------------------------------------------------------------------
Expand Down