Skip to content

Even more exports #276

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 5 commits into from
Mar 28, 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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: parsnip
Version: 0.0.5.9000
Version: 0.0.5.9001
Title: A Common API to Modeling and Analysis Functions
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).
Authors@R: c(
Expand Down
17 changes: 17 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ S3method(predict,model_spec)
S3method(predict,nullmodel)
S3method(predict_class,"_lognet")
S3method(predict_class,"_multnet")
S3method(predict_class,model_fit)
S3method(predict_classprob,"_lognet")
S3method(predict_classprob,"_multnet")
S3method(predict_classprob,model_fit)
S3method(predict_confint,model_fit)
S3method(predict_numeric,"_elnet")
S3method(predict_numeric,model_fit)
S3method(predict_quantile,model_fit)
S3method(predict_raw,"_elnet")
S3method(predict_raw,"_lognet")
S3method(predict_raw,"_multnet")
S3method(predict_raw,model_fit)
S3method(print,boost_tree)
S3method(print,control_parsnip)
S3method(print,decision_tree)
Expand Down Expand Up @@ -92,7 +98,10 @@ export(boost_tree)
export(check_empty_ellipse)
export(check_final_param)
export(control_parsnip)
export(convert_args)
export(convert_stan_interval)
export(decision_tree)
export(eval_args)
export(fit)
export(fit.model_spec)
export(fit_control)
Expand Down Expand Up @@ -122,6 +131,13 @@ export(null_value)
export(nullmodel)
export(pred_value_template)
export(predict.model_fit)
export(predict_class.model_fit)
export(predict_classprob.model_fit)
export(predict_confint.model_fit)
export(predict_numeric)
export(predict_numeric.model_fit)
export(predict_quantile.model_fit)
export(predict_raw.model_fit)
export(rand_forest)
export(rpart_train)
export(set_args)
Expand All @@ -144,6 +160,7 @@ export(svm_poly)
export(svm_rbf)
export(tidy.model_fit)
export(translate)
export(translate.default)
export(update_dot_check)
export(update_main_parameters)
export(varying)
Expand Down
10 changes: 10 additions & 0 deletions R/aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ maybe_multivariate <- function(results, object) {
results
}

#' Convenience function for intervals
#' @importFrom stats quantile
#' @export
#' @keywords internal
#' @param x A fitted model object
#' @param level Level of uncertainty for intervals
#' @param lower Is `level` the lower level?
convert_stan_interval <- function(x, level = 0.95, lower = TRUE) {
alpha <- (1 - level) / 2
if (!lower) {
Expand All @@ -24,6 +30,10 @@ convert_stan_interval <- function(x, level = 0.95, lower = TRUE) {
res
}

#' Make a table of arguments
#' @param model_name A character string for the model
#' @keywords internal
#' @export
convert_args <- function(model_name) {
envir <- get_model_env()

Expand Down
20 changes: 10 additions & 10 deletions R/aaa_multi_predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,18 @@ multi_predict_args.default <- function(object, ...) {
#' @export
#' @rdname has_multi_predict
multi_predict_args.model_fit <- function(object, ...) {
existing_mthds <- methods("multi_predict")
cls <- class(object)
tst <- paste0("multi_predict.", cls)
.fn <- tst[tst %in% existing_mthds]
if (length(.fn) == 0) {
return(NA_character_)
model_type <- class(object$spec)[1]
arg_info <- get_from_env(paste0(model_type, "_args"))
arg_info <- arg_info[arg_info$engine == object$spec$engine,]
arg_info <- arg_info[arg_info$has_submodel,]

if (nrow(arg_info) == 0) {
res <- NA_character_
} else {
res <- arg_info[["parsnip"]]
}

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

#' @export
Expand Down
5 changes: 5 additions & 0 deletions R/arguments.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ maybe_eval <- function(x) {
y
}

#' Evaluate parsnip model arguments
#' @export
#' @keywords internal
#' @param spec A model specification
#' @param ... Not used.
eval_args <- function(spec, ...) {
spec$args <- purrr::map(spec$args, maybe_eval)
spec$eng_args <- purrr::map(spec$eng_args, maybe_eval)
Expand Down
2 changes: 1 addition & 1 deletion R/linear_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
#' separately saved to disk. In a new session, the object can be
#' reloaded and reattached to the `parsnip` object.
#'
#' @seealso [[fit()], [set_engine()]
#' @seealso [fit()], [set_engine()]
#' @examples
#' linear_reg()
#' # Parameters can be represented by a placeholder:
Expand Down
2 changes: 1 addition & 1 deletion R/linear_reg_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ set_model_arg(
parsnip = "penalty",
original = "reg_param",
func = list(pkg = "dials", fun = "penalty"),
has_submodel = TRUE
has_submodel = FALSE
)

set_model_arg(
Expand Down
2 changes: 1 addition & 1 deletion R/logistic_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
#' separately saved to disk. In a new session, the object can be
#' reloaded and reattached to the `parsnip` object.
#'
#' @seealso [[fit()]
#' @seealso [fit()]
#' @examples
#' logistic_reg()
#' # Parameters can be represented by a placeholder:
Expand Down
2 changes: 1 addition & 1 deletion R/mars.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#' attached.
#'
#' @importFrom purrr map_lgl
#' @seealso [[fit()]
#' @seealso [fit()]
#' @examples
#' mars(mode = "regression", num_terms = 5)
#' @export
Expand Down
2 changes: 1 addition & 1 deletion R/mlp.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
#' \Sexpr[results=rd]{parsnip:::show_fit(parsnip:::mlp(mode = "regression"), "nnet")}
#'
#' @importFrom purrr map_lgl
#' @seealso [[fit()]
#' @seealso [fit()]
#' @examples
#' mlp(mode = "classification", penalty = 0.01)
#' # Parameters can be represented by a placeholder:
Expand Down
2 changes: 1 addition & 1 deletion R/multinom_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
#' separately saved to disk. In a new session, the object can be
#' reloaded and reattached to the `parsnip` object.
#'
#' @seealso [[fit()]
#' @seealso [fit()]
#' @examples
#' multinom_reg()
#' # Parameters can be represented by a placeholder:
Expand Down
2 changes: 1 addition & 1 deletion R/nearest_neighbor.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
#' on new data. This also means that a single value of that function's
#' `kernel` argument (a.k.a `weight_func` here) can be supplied
#'
#' @seealso [[fit()]
#' @seealso [fit()]
#'
#' @examples
#' nearest_neighbor(neighbors = 11)
Expand Down
20 changes: 10 additions & 10 deletions R/predict_class.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Other predict methods.
#
# These are internal functions not meant to be directly called by the user.
#
# @keywords internal
# @rdname other_predict
# @inheritParams predict.model_fit
# @method predict_class model_fit
# @export predict_class.model_fit
# @export
#' Other predict methods.
#'
#' These are internal functions not meant to be directly called by the user.
#'
#' @keywords internal
#' @rdname other_predict
#' @inheritParams predict.model_fit
#' @method predict_class model_fit
#' @export predict_class.model_fit
#' @export
predict_class.model_fit <- function(object, new_data, ...) {
if (object$spec$mode != "classification")
rlang::abort("`predict.model_fit()` is for predicting factor outcomes.")
Expand Down
12 changes: 6 additions & 6 deletions R/predict_classprob.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# @keywords internal
# @rdname other_predict
# @inheritParams predict.model_fit
# @method predict_classprob model_fit
# @export predict_classprob.model_fit
# @export
#' @keywords internal
#' @rdname other_predict
#' @inheritParams predict.model_fit
#' @method predict_classprob model_fit
#' @export predict_classprob.model_fit
#' @export
#' @importFrom tibble as_tibble is_tibble tibble
predict_classprob.model_fit <- function(object, new_data, ...) {
if (object$spec$mode != "classification")
Expand Down
20 changes: 10 additions & 10 deletions R/predict_interval.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# @keywords internal
# @rdname other_predict
# @param level A single numeric value between zero and one for the
# interval estimates.
# @param std_error A single logical for wether the standard error should be
# returned (assuming that the model can compute it).
# @inheritParams predict.model_fit
# @method predict_confint model_fit
# @export predict_confint.model_fit
# @export
#' @keywords internal
#' @rdname other_predict
#' @param level A single numeric value between zero and one for the
#' interval estimates.
#' @param std_error A single logical for wether the standard error should be
#' returned (assuming that the model can compute it).
#' @inheritParams predict.model_fit
#' @method predict_confint model_fit
#' @export predict_confint.model_fit
#' @export
predict_confint.model_fit <- function(object, new_data, level = 0.95, std_error = FALSE, ...) {

if (is.null(object$spec$method$pred$conf_int))
Expand Down
21 changes: 10 additions & 11 deletions R/predict_numeric.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# @keywords internal
# @rdname other_predict
# @inheritParams predict.model_fit
# @method predict_numeric model_fit
# @export predict_numeric.model_fit
# @export

#' @keywords internal
#' @rdname other_predict
#' @inheritParams predict.model_fit
#' @method predict_numeric model_fit
#' @export predict_numeric.model_fit
#' @export
predict_numeric.model_fit <- function(object, new_data, ...) {
if (object$spec$mode != "regression")
rlang::abort(glue::glue("`predict_numeric()` is for predicting numeric outcomes. ",
Expand Down Expand Up @@ -45,9 +44,9 @@ predict_numeric.model_fit <- function(object, new_data, ...) {
}


# @export
# @keywords internal
# @rdname other_predict
# @inheritParams predict_numeric.model_fit
#' @export
#' @keywords internal
#' @rdname other_predict
#' @inheritParams predict_numeric.model_fit
predict_numeric <- function(object, ...)
UseMethod("predict_numeric")
18 changes: 9 additions & 9 deletions R/predict_quantile.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# @keywords internal
# @rdname other_predict
# @param quant A vector of numbers between 0 and 1 for the quantile being
# predicted.
# @inheritParams predict.model_fit
# @method predict_quantile model_fit
# @export predict_quantile.model_fit
# @export
#' @keywords internal
#' @rdname other_predict
#' @param quant A vector of numbers between 0 and 1 for the quantile being
#' predicted.
#' @inheritParams predict.model_fit
#' @method predict_quantile model_fit
#' @export predict_quantile.model_fit
#' @export
predict_quantile.model_fit <-
function (object, new_data, quantile = (1:9)/10, ...) {
function(object, new_data, quantile = (1:9)/10, ...) {

if (is.null(object$spec$method$pred$quantile))
rlang::abort("No quantile prediction method defined for this engine.")
Expand Down
9 changes: 4 additions & 5 deletions R/predict_raw.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# @rdname predict.model_fit
# @inheritParams predict.model_fit
# @method predict_raw model_fit
# @export predict_raw.model_fit
# @export
#' @rdname predict.model_fit
#' @method predict_raw model_fit
#' @export predict_raw.model_fit
#' @export
predict_raw.model_fit <- function(object, new_data, opts = list(), ...) {
protected_args <- names(object$spec$method$pred$raw$args)
dup_args <- names(opts) %in% protected_args
Expand Down
2 changes: 1 addition & 1 deletion R/rand_forest.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
#' reloaded and reattached to the `parsnip` object.
#'
#' @importFrom purrr map_lgl
#' @seealso [[fit()]
#' @seealso [fit()]
#' @examples
#' rand_forest(mode = "classification", trees = 2000)
#' # Parameters can be represented by a placeholder:
Expand Down
2 changes: 1 addition & 1 deletion R/surv_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#' predictions when there is a stratification variable and can be
#' overridden in other cases.
#'
#' @seealso [[fit()], [survival::Surv()]
#' @seealso [fit()], [survival::Surv()]
#' @references Jackson, C. (2016). `flexsurv`: A Platform for Parametric Survival
#' Modeling in R. _Journal of Statistical Software_, 70(8), 1 - 33.
#' @examples
Expand Down
2 changes: 1 addition & 1 deletion R/svm_poly.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
#' \Sexpr[results=rd]{parsnip:::show_fit(parsnip:::svm_poly(mode = "regression"), "kernlab")}
#'
#' @importFrom purrr map_lgl
#' @seealso [[fit()]
#' @seealso [fit()]
#' @examples
#' svm_poly(mode = "classification", degree = 1.2)
#' # Parameters can be represented by a placeholder:
Expand Down
3 changes: 3 additions & 0 deletions R/translate.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#' It translates generic parameters to their counterparts.
#'
#' @param x A model specification.
#' @param engine The computational engine for the model (see `?set_engine`).
#' @param ... Not currently used.
#' @details
#' `translate()` produces a _template_ call that lacks the specific
Expand Down Expand Up @@ -47,7 +48,9 @@ translate <- function(x, ...)
#' @importFrom utils getFromNamespace
#' @importFrom purrr list_modify
#' @importFrom rlang lgl
#' @rdname translate
#' @export
#' @export translate.default
translate.default <- function(x, engine = x$engine, ...) {
check_empty_ellipse(...)
if (is.null(engine))
Expand Down
15 changes: 15 additions & 0 deletions man/convert_args.Rd

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

19 changes: 19 additions & 0 deletions man/convert_stan_interval.Rd

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

Loading