Skip to content

Commit e9d6773

Browse files
committed
test and documentation update
1 parent ee4b955 commit e9d6773

File tree

105 files changed

+975
-964
lines changed

Some content is hidden

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

105 files changed

+975
-964
lines changed

R/boost_tree.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ print.boost_tree <- function(x, ...) {
150150
#' @export
151151
#' @inheritParams boost_tree
152152
#' @param object A boosted tree model specification.
153+
#' @param ... Not used for `update`.
153154
#' @param fresh A logical for whether the arguments should be
154155
#' modified in-place of or replaced wholesale.
155156
#' @return An updated model specification.
@@ -166,7 +167,9 @@ update.boost_tree <-
166167
mtry = NULL, trees = NULL, min_n = NULL,
167168
tree_depth = NULL, learn_rate = NULL,
168169
loss_reduction = NULL, sample_size = NULL,
169-
fresh = FALSE) {
170+
fresh = FALSE, ...) {
171+
update_dot_check(...)
172+
170173
args <- list(
171174
mtry = enquo(mtry),
172175
trees = enquo(trees),

R/engines.R

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,35 @@ check_installs <- function(x) {
5252
}
5353
}
5454
}
55+
56+
#' Declare a computational engine and specific arguments
57+
#'
58+
#' `set_engine` is used to specify which package or system will be used
59+
#' to fit the model, along with any arguments specific to that software.
60+
#'
61+
#' @param object A model specification.
62+
#' @param engine A character string for the software that should
63+
#' be used to fit the model. This is highly dependent on the type
64+
#' of model (e.g. linear regression, random forest, etc.).
65+
#' @param ... Any optional arguments associated with the chosen computational
66+
#' engine. These are captured as quosures and can be `varying()`.
67+
#' @return An updated model specification.
68+
#' @examples
69+
#' # First, set general arguments using the standardized names
70+
#' mod <-
71+
#' logistic_reg(mixture = 1/3) %>%
72+
#' # now say how you want to fit the model and another other options
73+
#' set_engine("glmnet", nlambda = 10)
74+
#' translate(mod, engine = "glmnet")
75+
#' @export
76+
set_engine <- function(object, engine, ...) {
77+
if (!is.character(engine) | length(engine) != 1)
78+
stop("`engine` should be a single character value.", call. = FALSE)
79+
80+
object$engine <- engine
81+
object <- check_engine(object)
82+
83+
84+
object$others <- enquos(...)
85+
object
86+
}

R/fit.R

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
#' code by substituting arguments, and execute the model fit
1010
#' routine.
1111
#'
12-
#' @param object An object of class `model_spec`
12+
#' @param object An object of class `model_spec` that has a chosen engine
13+
#' (via [set_engine()]).
1314
#' @param formula An object of class "formula" (or one that can
1415
#' be coerced to that class): a symbolic description of the model
1516
#' to be fitted.
@@ -45,21 +46,20 @@
4546
#' library(dplyr)
4647
#' data("lending_club")
4748
#'
48-
#' lm_mod <- logistic_reg()
49+
#' lr_mod <- logistic_reg()
4950
#'
50-
#' lm_mod <- logistic_reg()
51+
#' lr_mod <- logistic_reg()
5152
#'
5253
#' using_formula <-
53-
#' lm_mod %>%
54-
#' fit(Class ~ funded_amnt + int_rate,
55-
#' data = lending_club,
56-
#' engine = "glm")
54+
#' lr_mod %>%
55+
#' set_engine("glm") %>%
56+
#' fit(Class ~ funded_amnt + int_rate, data = lending_club)
5757
#'
5858
#' using_xy <-
59-
#' lm_mod %>%
59+
#' lr_mod %>%
60+
#' set_engine("glm") %>%
6061
#' fit_xy(x = lending_club[, c("funded_amnt", "int_rate")],
61-
#' y = lending_club$Class,
62-
#' engine = "glm")
62+
#' y = lending_club$Class)
6363
#'
6464
#' using_formula
6565
#' using_xy
@@ -79,6 +79,7 @@
7979
#' The return value will also have a class related to the fitted model (e.g.
8080
#' `"_glm"`) before the base class of `"model_fit"`.
8181
#'
82+
#' @seealso [set_engine()], [fit_control()], `model_spec`, `model_fit`
8283
#' @param x A matrix or data frame of predictors.
8384
#' @param y A vector, matrix or data frame of outcome data.
8485
#' @rdname fit

R/linear_reg.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ print.linear_reg <- function(x, ...) {
154154
update.linear_reg <-
155155
function(object,
156156
penalty = NULL, mixture = NULL,
157-
fresh = FALSE) {
158-
157+
fresh = FALSE, ...) {
158+
update_dot_check(...)
159159
args <- list(
160160
penalty = enquo(penalty),
161161
mixture = enquo(mixture)

R/logistic_reg.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ print.logistic_reg <- function(x, ...) {
153153
update.logistic_reg <-
154154
function(object,
155155
penalty = NULL, mixture = NULL,
156-
fresh = FALSE) {
157-
156+
fresh = FALSE, ...) {
157+
update_dot_check(...)
158158
args <- list(
159159
penalty = enquo(penalty),
160160
mixture = enquo(mixture)

R/mars.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ print.mars <- function(x, ...) {
109109
update.mars <-
110110
function(object,
111111
num_terms = NULL, prod_degree = NULL, prune_method = NULL,
112-
fresh = FALSE) {
113-
112+
fresh = FALSE, ...) {
113+
update_dot_check(...)
114114
args <- list(
115115
num_terms = enquo(num_terms),
116116
prod_degree = enquo(prod_degree),
@@ -164,7 +164,7 @@ check_args.mars <- function(object) {
164164

165165
if (!is_varying(args$prune_method) &&
166166
!is.null(args$prune_method) &&
167-
is.character(args$prune_method))
167+
!is.character(args$prune_method))
168168
stop("`prune_method` should be a single string value", call. = FALSE)
169169

170170
invisible(object)

R/misc.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,16 @@ names0 <- function (num, prefix = "x") {
190190
ind <- gsub(" ", "0", ind)
191191
paste0(prefix, ind)
192192
}
193+
194+
195+
# ------------------------------------------------------------------------------
196+
197+
update_dot_check <- function(...) {
198+
dots <- enquos(...)
199+
if (length(dots) > 0)
200+
stop("Extra arguments will be ignored: ",
201+
paste0("`", names(dots), "`", collapse = ", "),
202+
call. = FALSE)
203+
invisible(NULL)
204+
}
205+

R/mlp.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ update.mlp <-
144144
function(object,
145145
hidden_units = NULL, penalty = NULL, dropout = NULL,
146146
epochs = NULL, activation = NULL,
147-
fresh = FALSE) {
148-
147+
fresh = FALSE, ...) {
148+
update_dot_check(...)
149149
args <- list(
150150
hidden_units = enquo(hidden_units),
151151
penalty = enquo(penalty),

R/model_object_docs.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,12 @@ NULL
175175
#' @examples
176176
#'
177177
#' # Keep the `x` matrix if the data are not too big.
178-
#' spec_obj <- linear_reg(x = ifelse(.obs() < 500, TRUE, FALSE))
178+
#' spec_obj <-
179+
#' linear_reg() %>%
180+
#' set_engine("lm", x = ifelse(.obs() < 500, TRUE, FALSE))
179181
#' spec_obj
180182
#'
181-
#' fit_obj <- fit(spec_obj, mpg ~ ., data = mtcars, engine = "lm")
183+
#' fit_obj <- fit(spec_obj, mpg ~ ., data = mtcars)
182184
#' fit_obj
183185
#'
184186
#' nrow(fit_obj$fit$x)

R/multinom_reg.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ print.multinom_reg <- function(x, ...) {
136136
update.multinom_reg <-
137137
function(object,
138138
penalty = NULL, mixture = NULL,
139-
fresh = FALSE) {
139+
fresh = FALSE, ...) {
140+
update_dot_check(...)
140141
args <- list(
141142
penalty = enquo(penalty),
142143
mixture = enquo(mixture)

0 commit comments

Comments
 (0)