Skip to content

Commit 5014b2e

Browse files
committed
check and load pacakges in predict() for #308
1 parent 031da1d commit 5014b2e

File tree

5 files changed

+11
-1
lines changed

5 files changed

+11
-1
lines changed

NAMESPACE

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ S3method(print,rand_forest)
5353
S3method(print,surv_reg)
5454
S3method(print,svm_poly)
5555
S3method(print,svm_rbf)
56+
S3method(req_pkgs,model_fit)
57+
S3method(req_pkgs,model_spec)
5658
S3method(tidy,model_fit)
5759
S3method(tidy,nullmodel)
5860
S3method(translate,boost_tree)
@@ -144,6 +146,7 @@ export(predict_raw)
144146
export(predict_raw.model_fit)
145147
export(rand_forest)
146148
export(repair_call)
149+
export(req_pkgs)
147150
export(rpart_train)
148151
export(set_args)
149152
export(set_dependency)

NEWS.md

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
* 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`.
2020

21+
* 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)
22+
23+
* The function `req_pkgs()` is a user interface to determining the required packages. (#308)
24+
2125
# parsnip 0.1.1
2226

2327
## New Features

R/aaa.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ utils::globalVariables(
6666
'lab', 'original', 'predicted_label', 'prediction', 'value', 'type',
6767
"neighbors", ".submodels", "has_submodel", "max_neighbor", "max_penalty",
6868
"max_terms", "max_tree", "model", "name", "num_terms", "penalty", "trees",
69-
"sub_neighbors", ".pred_class", "x", "y")
69+
"sub_neighbors", ".pred_class", "x", "y", "predictor_indicators")
7070
)
7171

7272
# nocov end

R/predict.R

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ predict.model_fit <- function(object, new_data, type = NULL, opts = list(), ...)
117117
return(NULL)
118118
}
119119

120+
check_installs(object$spec)
121+
load_libs(object$spec, quiet = TRUE)
122+
120123
other_args <- c("level", "std_error", "quantile") # "time" for survival probs later
121124
is_pred_arg <- names(the_dots) %in% other_args
122125
if (any(!is_pred_arg)) {

tests/testthat/mars_model.RData

30.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)