Skip to content

Commit 8fd1a87

Browse files
authored
Merge pull request #322 from tidymodels/install-mania
Package requirements and loading, fix pkgdown site
2 parents aa29bac + f21cadd commit 8fd1a87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1014
-562
lines changed

NAMESPACE

Lines changed: 3 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 0 deletions
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)) {

R/req_pkgs.R

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#' Determine required packages for a model
2+
#'
3+
#' @param x A model specification or fit.
4+
#' @param ... Not used.
5+
#' @return A character string of package names (if any).
6+
#' @details
7+
#' For a model specification, the engine must be set.
8+
#'
9+
#' The list does not include the `parsnip` package.
10+
#' @examples
11+
#' should_fail <- try(req_pkgs(linear_reg()), silent = TRUE)
12+
#' should_fail
13+
#'
14+
#' linear_reg() %>%
15+
#' set_engine("glmnet") %>%
16+
#' req_pkgs()
17+
#'
18+
#' linear_reg() %>%
19+
#' set_engine("lm") %>%
20+
#' fit(mpg ~ ., data = mtcars) %>%
21+
#' req_pkgs()
22+
#' @export
23+
req_pkgs <- function(x, ...) {
24+
UseMethod("req_pkgs")
25+
}
26+
27+
#' @export
28+
#' @rdname req_pkgs
29+
req_pkgs.model_spec <- function(x, ...) {
30+
if (is.null(x$engine)) {
31+
rlang::abort("Please set an engine.")
32+
}
33+
get_pkgs(x)
34+
}
35+
36+
#' @export
37+
#' @rdname req_pkgs
38+
req_pkgs.model_fit <- function(x, ...) {
39+
get_pkgs(x$spec)
40+
}
41+
42+
get_pkgs <- function(x) {
43+
cls <- class(x)[1]
44+
pkgs <-
45+
get_from_env(paste0(cls, "_pkgs")) %>%
46+
dplyr::filter(engine == x$engine)
47+
res <- pkgs$pkg[[1]]
48+
if (length(res) == 0) {
49+
res <- character(0)
50+
}
51+
res
52+
}
53+

docs/dev/articles/articles/Submodels.html

Lines changed: 17 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/dev/news/index.html

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/dev/pkgdown.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,14 @@ nav[data-toggle='toc'] .nav .nav > .active:focus > a {
244244

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

247-
.ref-index td {vertical-align: top; min-width: 100px}
247+
.ref-index td {vertical-align: top;}
248248
.ref-index .icon {width: 40px;}
249249
.ref-index .alias {width: 40%;}
250250
.ref-index-icons .alias {width: calc(40% - 40px);}
251251
.ref-index .title {width: 60%;}
252252

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

docs/dev/pkgdown.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
pandoc: 2.9.2.1
2-
pkgdown: 1.5.1.9000
3-
pkgdown_sha: ac78596154e403df5f4e683f2185d88225a0fea6
2+
pkgdown: 1.5.1
3+
pkgdown_sha: ~
44
articles:
55
Classification: articles/Classification.html
66
Models: articles/Models.html
77
Regression: articles/Regression.html
88
Scratch: articles/Scratch.html
99
Submodels: articles/Submodels.html
1010
parsnip_Intro: parsnip_Intro.html
11-
last_built: 2020-05-27T00:06Z
11+
last_built: 2020-05-30T23:54Z
1212
urls:
1313
reference: https://parsnip.tidymodels.org/reference
1414
article: https://parsnip.tidymodels.org/articles

0 commit comments

Comments
 (0)