Skip to content

Commit 9333a0d

Browse files
authored
Merge pull request #276 from tidymodels/even-more-exports
Even more exports
2 parents 8b73b3b + 488dce9 commit 9333a0d

37 files changed

+234
-82
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: parsnip
2-
Version: 0.0.5.9000
2+
Version: 0.0.5.9001
33
Title: A Common API to Modeling and Analysis Functions
44
Description: A common interface is provided to allow users to specify a model without having to remember the different argument names across different functions or computational engines (e.g. 'R', 'Spark', 'Stan', etc).
55
Authors@R: c(

NAMESPACE

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,18 @@ S3method(predict,model_spec)
2525
S3method(predict,nullmodel)
2626
S3method(predict_class,"_lognet")
2727
S3method(predict_class,"_multnet")
28+
S3method(predict_class,model_fit)
2829
S3method(predict_classprob,"_lognet")
2930
S3method(predict_classprob,"_multnet")
31+
S3method(predict_classprob,model_fit)
32+
S3method(predict_confint,model_fit)
3033
S3method(predict_numeric,"_elnet")
34+
S3method(predict_numeric,model_fit)
35+
S3method(predict_quantile,model_fit)
3136
S3method(predict_raw,"_elnet")
3237
S3method(predict_raw,"_lognet")
3338
S3method(predict_raw,"_multnet")
39+
S3method(predict_raw,model_fit)
3440
S3method(print,boost_tree)
3541
S3method(print,control_parsnip)
3642
S3method(print,decision_tree)
@@ -92,7 +98,10 @@ export(boost_tree)
9298
export(check_empty_ellipse)
9399
export(check_final_param)
94100
export(control_parsnip)
101+
export(convert_args)
102+
export(convert_stan_interval)
95103
export(decision_tree)
104+
export(eval_args)
96105
export(fit)
97106
export(fit.model_spec)
98107
export(fit_control)
@@ -122,6 +131,13 @@ export(null_value)
122131
export(nullmodel)
123132
export(pred_value_template)
124133
export(predict.model_fit)
134+
export(predict_class.model_fit)
135+
export(predict_classprob.model_fit)
136+
export(predict_confint.model_fit)
137+
export(predict_numeric)
138+
export(predict_numeric.model_fit)
139+
export(predict_quantile.model_fit)
140+
export(predict_raw.model_fit)
125141
export(rand_forest)
126142
export(rpart_train)
127143
export(set_args)
@@ -144,6 +160,7 @@ export(svm_poly)
144160
export(svm_rbf)
145161
export(tidy.model_fit)
146162
export(translate)
163+
export(translate.default)
147164
export(update_dot_check)
148165
export(update_main_parameters)
149166
export(varying)

R/aaa.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ maybe_multivariate <- function(results, object) {
1313
results
1414
}
1515

16+
#' Convenience function for intervals
1617
#' @importFrom stats quantile
18+
#' @export
19+
#' @keywords internal
20+
#' @param x A fitted model object
21+
#' @param level Level of uncertainty for intervals
22+
#' @param lower Is `level` the lower level?
1723
convert_stan_interval <- function(x, level = 0.95, lower = TRUE) {
1824
alpha <- (1 - level) / 2
1925
if (!lower) {
@@ -24,6 +30,10 @@ convert_stan_interval <- function(x, level = 0.95, lower = TRUE) {
2430
res
2531
}
2632

33+
#' Make a table of arguments
34+
#' @param model_name A character string for the model
35+
#' @keywords internal
36+
#' @export
2737
convert_args <- function(model_name) {
2838
envir <- get_model_env()
2939

R/aaa_multi_predict.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,18 @@ multi_predict_args.default <- function(object, ...) {
117117
#' @export
118118
#' @rdname has_multi_predict
119119
multi_predict_args.model_fit <- function(object, ...) {
120-
existing_mthds <- methods("multi_predict")
121-
cls <- class(object)
122-
tst <- paste0("multi_predict.", cls)
123-
.fn <- tst[tst %in% existing_mthds]
124-
if (length(.fn) == 0) {
125-
return(NA_character_)
120+
model_type <- class(object$spec)[1]
121+
arg_info <- get_from_env(paste0(model_type, "_args"))
122+
arg_info <- arg_info[arg_info$engine == object$spec$engine,]
123+
arg_info <- arg_info[arg_info$has_submodel,]
124+
125+
if (nrow(arg_info) == 0) {
126+
res <- NA_character_
127+
} else {
128+
res <- arg_info[["parsnip"]]
126129
}
127130

128-
.fn <- getFromNamespace(.fn, ns = "parsnip")
129-
omit <- c('object', 'new_data', 'type', '...')
130-
args <- names(formals(.fn))
131-
args[!(args %in% omit)]
131+
res
132132
}
133133

134134
#' @export

R/arguments.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ maybe_eval <- function(x) {
103103
y
104104
}
105105

106+
#' Evaluate parsnip model arguments
107+
#' @export
108+
#' @keywords internal
109+
#' @param spec A model specification
110+
#' @param ... Not used.
106111
eval_args <- function(spec, ...) {
107112
spec$args <- purrr::map(spec$args, maybe_eval)
108113
spec$eng_args <- purrr::map(spec$eng_args, maybe_eval)

R/linear_reg.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
#' separately saved to disk. In a new session, the object can be
106106
#' reloaded and reattached to the `parsnip` object.
107107
#'
108-
#' @seealso [[fit()], [set_engine()]
108+
#' @seealso [fit()], [set_engine()]
109109
#' @examples
110110
#' linear_reg()
111111
#' # Parameters can be represented by a placeholder:

R/linear_reg_data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ set_model_arg(
293293
parsnip = "penalty",
294294
original = "reg_param",
295295
func = list(pkg = "dials", fun = "penalty"),
296-
has_submodel = TRUE
296+
has_submodel = FALSE
297297
)
298298

299299
set_model_arg(

R/logistic_reg.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
#' separately saved to disk. In a new session, the object can be
105105
#' reloaded and reattached to the `parsnip` object.
106106
#'
107-
#' @seealso [[fit()]
107+
#' @seealso [fit()]
108108
#' @examples
109109
#' logistic_reg()
110110
#' # Parameters can be represented by a placeholder:

R/mars.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
#' attached.
6363
#'
6464
#' @importFrom purrr map_lgl
65-
#' @seealso [[fit()]
65+
#' @seealso [fit()]
6666
#' @examples
6767
#' mars(mode = "regression", num_terms = 5)
6868
#' @export

R/mlp.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
#' \Sexpr[results=rd]{parsnip:::show_fit(parsnip:::mlp(mode = "regression"), "nnet")}
8585
#'
8686
#' @importFrom purrr map_lgl
87-
#' @seealso [[fit()]
87+
#' @seealso [fit()]
8888
#' @examples
8989
#' mlp(mode = "classification", penalty = 0.01)
9090
#' # Parameters can be represented by a placeholder:

R/multinom_reg.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
#' separately saved to disk. In a new session, the object can be
9292
#' reloaded and reattached to the `parsnip` object.
9393
#'
94-
#' @seealso [[fit()]
94+
#' @seealso [fit()]
9595
#' @examples
9696
#' multinom_reg()
9797
#' # Parameters can be represented by a placeholder:

R/nearest_neighbor.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
#' on new data. This also means that a single value of that function's
7171
#' `kernel` argument (a.k.a `weight_func` here) can be supplied
7272
#'
73-
#' @seealso [[fit()]
73+
#' @seealso [fit()]
7474
#'
7575
#' @examples
7676
#' nearest_neighbor(neighbors = 11)

R/predict_class.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# Other predict methods.
2-
#
3-
# These are internal functions not meant to be directly called by the user.
4-
#
5-
# @keywords internal
6-
# @rdname other_predict
7-
# @inheritParams predict.model_fit
8-
# @method predict_class model_fit
9-
# @export predict_class.model_fit
10-
# @export
1+
#' Other predict methods.
2+
#'
3+
#' These are internal functions not meant to be directly called by the user.
4+
#'
5+
#' @keywords internal
6+
#' @rdname other_predict
7+
#' @inheritParams predict.model_fit
8+
#' @method predict_class model_fit
9+
#' @export predict_class.model_fit
10+
#' @export
1111
predict_class.model_fit <- function(object, new_data, ...) {
1212
if (object$spec$mode != "classification")
1313
rlang::abort("`predict.model_fit()` is for predicting factor outcomes.")

R/predict_classprob.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# @keywords internal
2-
# @rdname other_predict
3-
# @inheritParams predict.model_fit
4-
# @method predict_classprob model_fit
5-
# @export predict_classprob.model_fit
6-
# @export
1+
#' @keywords internal
2+
#' @rdname other_predict
3+
#' @inheritParams predict.model_fit
4+
#' @method predict_classprob model_fit
5+
#' @export predict_classprob.model_fit
6+
#' @export
77
#' @importFrom tibble as_tibble is_tibble tibble
88
predict_classprob.model_fit <- function(object, new_data, ...) {
99
if (object$spec$mode != "classification")

R/predict_interval.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# @keywords internal
2-
# @rdname other_predict
3-
# @param level A single numeric value between zero and one for the
4-
# interval estimates.
5-
# @param std_error A single logical for wether the standard error should be
6-
# returned (assuming that the model can compute it).
7-
# @inheritParams predict.model_fit
8-
# @method predict_confint model_fit
9-
# @export predict_confint.model_fit
10-
# @export
1+
#' @keywords internal
2+
#' @rdname other_predict
3+
#' @param level A single numeric value between zero and one for the
4+
#' interval estimates.
5+
#' @param std_error A single logical for wether the standard error should be
6+
#' returned (assuming that the model can compute it).
7+
#' @inheritParams predict.model_fit
8+
#' @method predict_confint model_fit
9+
#' @export predict_confint.model_fit
10+
#' @export
1111
predict_confint.model_fit <- function(object, new_data, level = 0.95, std_error = FALSE, ...) {
1212

1313
if (is.null(object$spec$method$pred$conf_int))

R/predict_numeric.R

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
# @keywords internal
2-
# @rdname other_predict
3-
# @inheritParams predict.model_fit
4-
# @method predict_numeric model_fit
5-
# @export predict_numeric.model_fit
6-
# @export
7-
1+
#' @keywords internal
2+
#' @rdname other_predict
3+
#' @inheritParams predict.model_fit
4+
#' @method predict_numeric model_fit
5+
#' @export predict_numeric.model_fit
6+
#' @export
87
predict_numeric.model_fit <- function(object, new_data, ...) {
98
if (object$spec$mode != "regression")
109
rlang::abort(glue::glue("`predict_numeric()` is for predicting numeric outcomes. ",
@@ -45,9 +44,9 @@ predict_numeric.model_fit <- function(object, new_data, ...) {
4544
}
4645

4746

48-
# @export
49-
# @keywords internal
50-
# @rdname other_predict
51-
# @inheritParams predict_numeric.model_fit
47+
#' @export
48+
#' @keywords internal
49+
#' @rdname other_predict
50+
#' @inheritParams predict_numeric.model_fit
5251
predict_numeric <- function(object, ...)
5352
UseMethod("predict_numeric")

R/predict_quantile.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# @keywords internal
2-
# @rdname other_predict
3-
# @param quant A vector of numbers between 0 and 1 for the quantile being
4-
# predicted.
5-
# @inheritParams predict.model_fit
6-
# @method predict_quantile model_fit
7-
# @export predict_quantile.model_fit
8-
# @export
1+
#' @keywords internal
2+
#' @rdname other_predict
3+
#' @param quant A vector of numbers between 0 and 1 for the quantile being
4+
#' predicted.
5+
#' @inheritParams predict.model_fit
6+
#' @method predict_quantile model_fit
7+
#' @export predict_quantile.model_fit
8+
#' @export
99
predict_quantile.model_fit <-
10-
function (object, new_data, quantile = (1:9)/10, ...) {
10+
function(object, new_data, quantile = (1:9)/10, ...) {
1111

1212
if (is.null(object$spec$method$pred$quantile))
1313
rlang::abort("No quantile prediction method defined for this engine.")

R/predict_raw.R

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# @rdname predict.model_fit
2-
# @inheritParams predict.model_fit
3-
# @method predict_raw model_fit
4-
# @export predict_raw.model_fit
5-
# @export
1+
#' @rdname predict.model_fit
2+
#' @method predict_raw model_fit
3+
#' @export predict_raw.model_fit
4+
#' @export
65
predict_raw.model_fit <- function(object, new_data, opts = list(), ...) {
76
protected_args <- names(object$spec$method$pred$raw$args)
87
dup_args <- names(opts) %in% protected_args

R/rand_forest.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
#' reloaded and reattached to the `parsnip` object.
9595
#'
9696
#' @importFrom purrr map_lgl
97-
#' @seealso [[fit()]
97+
#' @seealso [fit()]
9898
#' @examples
9999
#' rand_forest(mode = "classification", trees = 2000)
100100
#' # Parameters can be represented by a placeholder:

R/surv_reg.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
#' predictions when there is a stratification variable and can be
6565
#' overridden in other cases.
6666
#'
67-
#' @seealso [[fit()], [survival::Surv()]
67+
#' @seealso [fit()], [survival::Surv()]
6868
#' @references Jackson, C. (2016). `flexsurv`: A Platform for Parametric Survival
6969
#' Modeling in R. _Journal of Statistical Software_, 70(8), 1 - 33.
7070
#' @examples

R/svm_poly.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
#' \Sexpr[results=rd]{parsnip:::show_fit(parsnip:::svm_poly(mode = "regression"), "kernlab")}
5959
#'
6060
#' @importFrom purrr map_lgl
61-
#' @seealso [[fit()]
61+
#' @seealso [fit()]
6262
#' @examples
6363
#' svm_poly(mode = "classification", degree = 1.2)
6464
#' # Parameters can be represented by a placeholder:

R/translate.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#' It translates generic parameters to their counterparts.
66
#'
77
#' @param x A model specification.
8+
#' @param engine The computational engine for the model (see `?set_engine`).
89
#' @param ... Not currently used.
910
#' @details
1011
#' `translate()` produces a _template_ call that lacks the specific
@@ -47,7 +48,9 @@ translate <- function(x, ...)
4748
#' @importFrom utils getFromNamespace
4849
#' @importFrom purrr list_modify
4950
#' @importFrom rlang lgl
51+
#' @rdname translate
5052
#' @export
53+
#' @export translate.default
5154
translate.default <- function(x, engine = x$engine, ...) {
5255
check_empty_ellipse(...)
5356
if (is.null(engine))

man/convert_args.Rd

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

man/convert_stan_interval.Rd

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

0 commit comments

Comments
 (0)