Skip to content
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

Package requirements and loading, fix pkgdown site #322

Merged
merged 4 commits into from
May 31, 2020
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
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ S3method(print,rand_forest)
S3method(print,surv_reg)
S3method(print,svm_poly)
S3method(print,svm_rbf)
S3method(req_pkgs,model_fit)
S3method(req_pkgs,model_spec)
S3method(tidy,model_fit)
S3method(tidy,nullmodel)
S3method(translate,boost_tree)
Expand Down Expand Up @@ -144,6 +146,7 @@ export(predict_raw)
export(predict_raw.model_fit)
export(rand_forest)
export(repair_call)
export(req_pkgs)
export(rpart_train)
export(set_args)
export(set_dependency)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

* A function named `repair_call()` was added. This can help change the underlying models `call` object to better reflect what they would have obtained if the model function had been used directly (instead of via `parsnip`). This is only useful when the user chooses a formula interface and the model uses a formula interface. It will also be of limited use when a recipes is used to construct the feature set in `workflows` or `tune`.

* The `predict()` function now checks to see if required modeling packages are installed. The packages are loaded (but not attached). (#249) (#308) (tidymodels/workflows#45)

* The function `req_pkgs()` is a user interface to determining the required packages. (#308)

# parsnip 0.1.1

## New Features
Expand Down
2 changes: 1 addition & 1 deletion R/aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ utils::globalVariables(
'lab', 'original', 'predicted_label', 'prediction', 'value', 'type',
"neighbors", ".submodels", "has_submodel", "max_neighbor", "max_penalty",
"max_terms", "max_tree", "model", "name", "num_terms", "penalty", "trees",
"sub_neighbors", ".pred_class", "x", "y")
"sub_neighbors", ".pred_class", "x", "y", "predictor_indicators")
)

# nocov end
3 changes: 3 additions & 0 deletions R/predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ predict.model_fit <- function(object, new_data, type = NULL, opts = list(), ...)
return(NULL)
}

check_installs(object$spec)
load_libs(object$spec, quiet = TRUE)

other_args <- c("level", "std_error", "quantile") # "time" for survival probs later
is_pred_arg <- names(the_dots) %in% other_args
if (any(!is_pred_arg)) {
Expand Down
53 changes: 53 additions & 0 deletions R/req_pkgs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#' Determine required packages for a model
#'
#' @param x A model specification or fit.
#' @param ... Not used.
#' @return A character string of package names (if any).
#' @details
#' For a model specification, the engine must be set.
#'
#' The list does not include the `parsnip` package.
#' @examples
#' should_fail <- try(req_pkgs(linear_reg()), silent = TRUE)
#' should_fail
#'
#' linear_reg() %>%
#' set_engine("glmnet") %>%
#' req_pkgs()
#'
#' linear_reg() %>%
#' set_engine("lm") %>%
#' fit(mpg ~ ., data = mtcars) %>%
#' req_pkgs()
#' @export
req_pkgs <- function(x, ...) {
UseMethod("req_pkgs")
}

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

#' @export
#' @rdname req_pkgs
req_pkgs.model_fit <- function(x, ...) {
get_pkgs(x$spec)
}

get_pkgs <- function(x) {
cls <- class(x)[1]
pkgs <-
get_from_env(paste0(cls, "_pkgs")) %>%
dplyr::filter(engine == x$engine)
res <- pkgs$pkg[[1]]
if (length(res) == 0) {
res <- character(0)
}
res
}

35 changes: 17 additions & 18 deletions docs/dev/articles/articles/Submodels.html

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

2 changes: 2 additions & 0 deletions docs/dev/news/index.html

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

4 changes: 2 additions & 2 deletions docs/dev/pkgdown.css
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,14 @@ nav[data-toggle='toc'] .nav .nav > .active:focus > a {

.ref-index th {font-weight: normal;}

.ref-index td {vertical-align: top; min-width: 100px}
.ref-index td {vertical-align: top;}
.ref-index .icon {width: 40px;}
.ref-index .alias {width: 40%;}
.ref-index-icons .alias {width: calc(40% - 40px);}
.ref-index .title {width: 60%;}

.ref-arguments th {text-align: right; padding-right: 10px;}
.ref-arguments th, .ref-arguments td {vertical-align: top; min-width: 100px}
.ref-arguments th, .ref-arguments td {vertical-align: top;}
.ref-arguments .name {width: 20%;}
.ref-arguments .desc {width: 80%;}

Expand Down
6 changes: 3 additions & 3 deletions docs/dev/pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
pandoc: 2.9.2.1
pkgdown: 1.5.1.9000
pkgdown_sha: ac78596154e403df5f4e683f2185d88225a0fea6
pkgdown: 1.5.1
pkgdown_sha: ~
articles:
Classification: articles/Classification.html
Models: articles/Models.html
Regression: articles/Regression.html
Scratch: articles/Scratch.html
Submodels: articles/Submodels.html
parsnip_Intro: parsnip_Intro.html
last_built: 2020-05-27T00:06Z
last_built: 2020-05-30T23:54Z
urls:
reference: https://parsnip.tidymodels.org/reference
article: https://parsnip.tidymodels.org/articles
Expand Down
Loading