Skip to content
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 R/arguments.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ check_others <- function(args, obj, core_args) {
#'
#' @export
set_args <- function(object, ...) {
the_dots <- list(...)
the_dots <- enquos(...)
if (length(the_dots) == 0)
stop("Please pass at least one named argument.", call. = FALSE)
main_args <- names(object$args)
Expand Down
38 changes: 26 additions & 12 deletions R/boost_tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@
#' }
#' These arguments are converted to their specific names at the
#' time that the model is fit. Other options and argument can be
#' set using the `others` argument. If left to their defaults
#' set using the `...` slot. If left to their defaults
#' here (`NULL`), the values are taken from the underlying model
#' functions. If parameters need to be modified, `update` can be used
#' in lieu of recreating the object from scratch.
#'
#' @param mode A single character string for the type of model.
#' Possible values for this model are "unknown", "regression", or
#' "classification".
#' @param others A named list of arguments to be used by the
#' underlying models (e.g., `xgboost::xgb.train`, etc.). .
#' @param mtry An number for the number (or proportion) of predictors that will
#' be randomly sampled at each split when creating the tree models (`xgboost`
#' only).
Expand All @@ -48,8 +46,11 @@
#' @param sample_size An number for the number (or proportion) of data that is
#' exposed to the fitting routine. For `xgboost`, the sampling is done at at
#' each iteration while `C5.0` samples once during traning.
#' @param ... Used for method consistency. Any arguments passed to
#' the ellipses will result in an error. Use `others` instead.
#' @param ... Other arguments to pass to the specific engine's
#' model fit function (see the Engine Details section below). This
#' should not include arguments defined by the main parameters to
#' this function. For the `update` function, the ellipses can
#' contain the primary arguments or any others.
#' @details
#' The data given to the function are not saved and are only used
#' to determine the _mode_ of the model. For `boost_tree`, the
Expand All @@ -62,12 +63,15 @@
#' \item \pkg{Spark}: `"spark"`
#' }
#'
#' Main parameter arguments (and those in `others`) can avoid
#' Main parameter arguments (and those in `...`) can avoid
#' evaluation until the underlying function is executed by wrapping the
#' argument in [rlang::expr()] (e.g. `mtry = expr(floor(sqrt(p)))`).
#'
#'
#' @section Engine Details:
#'
#' Engines may have pre-set default arguments when executing the
#' model fit call. These can be changed by using the `others`
#' model fit call. These can be changed by using the `...`
#' argument to pass in the preferred values. For this type of
#' model, the template of the fit calls are:
#'
Expand Down Expand Up @@ -114,13 +118,18 @@

boost_tree <-
function(mode = "unknown",
...,
mtry = NULL, trees = NULL, min_n = NULL,
tree_depth = NULL, learn_rate = NULL,
loss_reduction = NULL,
sample_size = NULL,
others = list()) {
check_empty_ellipse(...)
...) {
others <- enquos(...)
mtry <- enquo(mtry)
trees <- enquo(trees)
min_n <- enquo(min_n)
learn_rate <- enquo(learn_rate)
loss_reduction <- enquo(loss_reduction)
sample_size <- enquo(sample_size)

if (!(mode %in% boost_tree_modes))
stop("`mode` should be one of: ",
Expand Down Expand Up @@ -184,10 +193,15 @@ update.boost_tree <-
mtry = NULL, trees = NULL, min_n = NULL,
tree_depth = NULL, learn_rate = NULL,
loss_reduction = NULL, sample_size = NULL,
others = list(),
fresh = FALSE,
...) {
check_empty_ellipse(...)
others <- enquos(...)
mtry <- enquo(mtry)
trees <- enquo(trees)
min_n <- enquo(min_n)
learn_rate <- enquo(learn_rate)
loss_reduction <- enquo(loss_reduction)
sample_size <- enquo(sample_size)

args <- list(
mtry = mtry, trees = trees, min_n = min_n, tree_depth = tree_depth,
Expand Down
34 changes: 15 additions & 19 deletions R/linear_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,19 @@
#' }
#' These arguments are converted to their specific names at the
#' time that the model is fit. Other options and argument can be
#' set using the `others` argument. If left to their defaults
#' set using the `...` slot. If left to their defaults
#' here (`NULL`), the values are taken from the underlying model
#' functions. If parameters need to be modified, `update` can be used
#' in lieu of recreating the object from scratch.
#' @inheritParams boost_tree
#' @param mode A single character string for the type of model.
#' The only possible value for this model is "regression".
#' @param others A named list of arguments to be used by the
#' underlying models (e.g., `stats::lm`,
#' `rstanarm::stan_glm`, etc.). These are not evaluated
#' until the model is fit and will be substituted into the model
#' fit expression.
#' @param penalty An non-negative number representing the
#' total amount of regularization (`glmnet` and `spark` only).
#' @param mixture A number between zero and one (inclusive) that
#' represents the proportion of regularization that is used for the
#' L2 penalty (i.e. weight decay, or ridge regression) versus L1
#' (the lasso) (`glmnet` and `spark` only).
#' @param ... Used for S3 method consistency. Any arguments passed to
#' the ellipses will result in an error. Use `others` instead.
#'
#' @details
#' The data given to the function are not saved and are only used
Expand All @@ -45,8 +39,10 @@
#' \item \pkg{Spark}: `"spark"`
#' }
#'
#' @section Engine Details:
#'
#' Engines may have pre-set default arguments when executing the
#' model fit call. These can be changed by using the `others`
#' model fit call. These can be changed by using the `...`
#' argument to pass in the preferred values. For this type of
#' model, the template of the fit calls are:
#'
Expand Down Expand Up @@ -105,11 +101,13 @@
#' @importFrom purrr map_lgl
linear_reg <-
function(mode = "regression",
...,
penalty = NULL,
mixture = NULL,
others = list()) {
check_empty_ellipse(...)
...) {
others <- enquos(...)
penalty <- enquo(penalty)
mixture <- enquo(mixture)

if (!(mode %in% linear_reg_modes))
stop(
"`mode` should be one of: ",
Expand All @@ -121,7 +119,7 @@ linear_reg <-
stop("The amount of regularization should be >= 0", call. = FALSE)
if (is.numeric(mixture) && (mixture < 0 | mixture > 1))
stop("The mixture proportion should be within [0,1]", call. = FALSE)
if (length(mixture) > 1)
if (is.numeric(mixture) && length(mixture) > 1)
stop("Only one value of `mixture` is allowed.", call. = FALSE)

args <- list(penalty = penalty, mixture = mixture)
Expand Down Expand Up @@ -156,11 +154,8 @@ print.linear_reg <- function(x, ...) {

# ------------------------------------------------------------------------------

#' @inheritParams linear_reg
#' @inheritParams update.boost_tree
#' @param object A linear regression model specification.
#' @param fresh A logical for whether the arguments should be
#' modified in-place of or replaced wholesale.
#' @return An updated model specification.
#' @examples
#' model <- linear_reg(penalty = 10, mixture = 0.1)
#' model
Expand All @@ -172,10 +167,11 @@ print.linear_reg <- function(x, ...) {
update.linear_reg <-
function(object,
penalty = NULL, mixture = NULL,
others = list(),
fresh = FALSE,
...) {
check_empty_ellipse(...)
others <- enquos(...)
penalty <- enquo(penalty)
mixture <- enquo(mixture)

if (is.numeric(penalty) && penalty < 0)
stop("The amount of regularization should be >= 0", call. = FALSE)
Expand Down
32 changes: 14 additions & 18 deletions R/logistic_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,19 @@
#' }
#' These arguments are converted to their specific names at the
#' time that the model is fit. Other options and argument can be
#' set using the `others` argument. If left to their defaults
#' set using the `...` slot. If left to their defaults
#' here (`NULL`), the values are taken from the underlying model
#' functions. If parameters need to be modified, `update` can be used
#' in lieu of recreating the object from scratch.
#' @inheritParams boost_tree
#' @param mode A single character string for the type of model.
#' The only possible value for this model is "classification".
#' @param others A named list of arguments to be used by the
#' underlying models (e.g., `stats::glm`,
#' `rstanarm::stan_glm`, etc.). These are not evaluated
#' until the model is fit and will be substituted into the model
#' fit expression.
#' @param penalty An non-negative number representing the
#' total amount of regularization (`glmnet` and `spark` only).
#' @param mixture A number between zero and one (inclusive) that
#' represents the proportion of regularization that is used for the
#' L2 penalty (i.e. weight decay, or ridge regression) versus L1
#' (the lasso) (`glmnet` and `spark` only).
#' @param ... Used for S3 method consistency. Any arguments passed to
#' the ellipses will result in an error. Use `others` instead.
#' @details
#' For `logistic_reg`, the mode will always be "classification".
#'
Expand All @@ -42,8 +36,10 @@
#' \item \pkg{Spark}: `"spark"`
#' }
#'
#' @section Engine Details:
#'
#' Engines may have pre-set default arguments when executing the
#' model fit call. These can be changed by using the `others`
#' model fit call. These can be changed by using the `...`
#' argument to pass in the preferred values. For this type of
#' model, the template of the fit calls are:
#'
Expand Down Expand Up @@ -103,11 +99,13 @@
#' @importFrom purrr map_lgl
logistic_reg <-
function(mode = "classification",
...,
penalty = NULL,
mixture = NULL,
others = list()) {
check_empty_ellipse(...)
...) {
others <- enquos(...)
penalty <- enquo(penalty)
mixture <- enquo(mixture)

if (!(mode %in% logistic_reg_modes))
stop(
"`mode` should be one of: ",
Expand Down Expand Up @@ -152,11 +150,8 @@ print.logistic_reg <- function(x, ...) {

# ------------------------------------------------------------------------------

#' @inheritParams logistic_reg
#' @inheritParams update.boost_tree
#' @param object A logistic regression model specification.
#' @param fresh A logical for whether the arguments should be
#' modified in-place of or replaced wholesale.
#' @return An updated model specification.
#' @examples
#' model <- logistic_reg(penalty = 10, mixture = 0.1)
#' model
Expand All @@ -168,10 +163,11 @@ print.logistic_reg <- function(x, ...) {
update.logistic_reg <-
function(object,
penalty = NULL, mixture = NULL,
others = list(),
fresh = FALSE,
...) {
check_empty_ellipse(...)
others <- enquos(...)
penalty <- enquo(penalty)
mixture <- enquo(mixture)

if (is.numeric(penalty) && penalty < 0)
stop("The amount of regularization should be >= 0", call. = FALSE)
Expand Down
4 changes: 2 additions & 2 deletions R/logistic_reg_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ logistic_reg_glm_data <-
func = c(pkg = "stats", fun = "glm"),
defaults =
list(
family = expr(binomial)
family = expr(stats::binomial)
)
),
classes = list(
Expand Down Expand Up @@ -151,7 +151,7 @@ logistic_reg_stan_data <-
func = c(pkg = "rstanarm", fun = "stan_glm"),
defaults =
list(
family = expr(binomial)
family = expr(stats::binomial)
)
),
classes = list(
Expand Down
37 changes: 17 additions & 20 deletions R/mars.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,20 @@
#' }
#' These arguments are converted to their specific names at the
#' time that the model is fit. Other options and argument can be
#' set using the `others` argument. If left to their defaults
#' set using the `...` slot. If left to their defaults
#' here (`NULL`), the values are taken from the underlying model
#' functions. If parameters need to be modified, `update` can be used
#' in lieu of recreating the object from scratch.
#'
#' @inheritParams boost_tree
#' @param mode A single character string for the type of model.
#' Possible values for this model are "unknown", "regression", or
#' "classification".
#' @param others A named list of arguments to be used by the
#' underlying models (e.g., `earth::earth`, etc.). If the outcome is a factor
#' and `mode = "classification"`, `others` can include the `glm` argument to
#' `earth::earth`. If this argument is not passed, it will be added prior to
#' the fitting occurs.
#' @param num_terms The number of features that will be retained in the
#' final model, including the intercept.
#' @param prod_degree The highest possible interaction degree.
#' @param prune_method The pruning method.
#' @param ... Used for method consistency. Any arguments passed to
#' the ellipses will result in an error. Use `others` instead.
#' @details Main parameter arguments (and those in `others`) can avoid
#' @details Main parameter arguments (and those in `...`) can avoid
#' evaluation until the underlying function is executed by wrapping the
#' argument in [rlang::expr()].
#'
Expand All @@ -46,8 +40,10 @@
#' \item \pkg{R}: `"earth"`
#' }
#'
#' @section Engine Details:
#'
#' Engines may have pre-set default arguments when executing the
#' model fit call. These can be changed by using the `others`
#' model fit call. These can be changed by using the `...`
#' argument to pass in the preferred values. For this type of
#' model, the template of the fit calls are:
#'
Expand All @@ -71,10 +67,12 @@

mars <-
function(mode = "unknown",
...,
num_terms = NULL, prod_degree = NULL, prune_method = NULL,
others = list()) {
check_empty_ellipse(...)
...) {
others <- enquos(...)
num_terms <- enquo(num_terms)
prod_degree <- enquo(prod_degree)
prune_method <- enquo(prune_method)

if (!(mode %in% mars_modes))
stop("`mode` should be one of: ",
Expand All @@ -87,7 +85,7 @@ mars <-
stop("`num_terms` should be >= 1", call. = FALSE)
if (!is_varying(prune_method) &&
!is.null(prune_method) &&
!is.character(prune_method))
is.character(prune_method))
stop("`prune_method` should be a single string value", call. = FALSE)

args <- list(num_terms = num_terms,
Expand Down Expand Up @@ -118,11 +116,8 @@ print.mars <- function(x, ...) {
# ------------------------------------------------------------------------------

#' @export
#' @inheritParams mars
#' @inheritParams update.boost_tree
#' @param object A MARS model specification.
#' @param fresh A logical for whether the arguments should be
#' modified in-place of or replaced wholesale.
#' @return An updated model specification.
#' @examples
#' model <- mars(num_terms = 10, prune_method = "none")
#' model
Expand All @@ -134,10 +129,12 @@ print.mars <- function(x, ...) {
update.mars <-
function(object,
num_terms = NULL, prod_degree = NULL, prune_method = NULL,
others = list(),
fresh = FALSE,
...) {
check_empty_ellipse(...)
others <- enquos(...)
num_terms <- enquo(num_terms)
prod_degree <- enquo(prod_degree)
prune_method <- enquo(prune_method)

args <- list(num_terms = num_terms,
prod_degree = prod_degree,
Expand Down
Loading