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: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export(predict_predint.model_fit)
export(predict_raw)
export(predict_raw.model_fit)
export(rand_forest)
export(set_args)
export(set_mode)
export(show_call)
export(surv_reg)
export(translate)
Expand Down
53 changes: 53 additions & 0 deletions R/arguments.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,56 @@ check_others <- function(args, obj, core_args) {
}
args
}

#' Change elements of a model specification
#'
#' `set_args` can be used to modify the arguments of a model specification while
#' `set_mode` is used to change the model's mode.
#'
#' @param object A model specification.
#' @param ... One or more named model arguments.
#' @param mode A character string for the model type (e.g. "classification" or
#' "regression")
#' @return An updated model object.
#' @details `set_args` will replace existing values of the arguments.
#'
#' @examples
#' rand_forest()
#'
#' rand_forest() %>%
#' set_args(mtry = 3, importance = TRUE) %>%
#' set_mode("regression")
#'
#' @export
set_args <- function(object, ...) {
the_dots <- list(...)
if (length(the_dots) == 0)
stop("Please pass at least one named argument.", call. = FALSE)
main_args <- names(object$args)
new_args <- names(the_dots)
for (i in new_args) {
if (any(main_args == i)) {
object$args[[i]] <- the_dots[[i]]
} else {
object$others[[i]] <- the_dots[[i]]
}
}
object
}

#' @rdname set_args
#' @export
set_mode <- function(object, mode) {
if (is.null(mode))
return(object)
mode <- mode[1]
if (!(any(all_modes == mode))) {
stop("`mode` should be one of ",
paste0("'", all_modes, "'", collapse = ", "),
call. = FALSE)
}
object$mode <- mode
object
}


2 changes: 2 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ reference:
- model_fit
- model_spec
- predict.model_fit
- set_args
- set_mode
- translate
- varying
- varying_args
Expand Down
92 changes: 43 additions & 49 deletions docs/articles/articles/Classification.html

Large diffs are not rendered by default.

31 changes: 15 additions & 16 deletions docs/articles/articles/Regression.html

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

4 changes: 2 additions & 2 deletions docs/articles/articles/Scratch.html

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

Loading