Skip to content

Commit 3facc66

Browse files
committed
air formatting
1 parent 20b7bd2 commit 3facc66

File tree

1 file changed

+71
-68
lines changed

1 file changed

+71
-68
lines changed

R/fit.R

Lines changed: 71 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,13 @@
109109
#' @export
110110
#' @export fit.model_spec
111111
fit.model_spec <-
112-
function(object,
113-
formula,
114-
data,
115-
case_weights = NULL,
116-
control = control_parsnip(),
117-
...
112+
function(
113+
object,
114+
formula,
115+
data,
116+
case_weights = NULL,
117+
control = control_parsnip(),
118+
...
118119
) {
119120
if (object$mode == "unknown") {
120121
cli::cli_abort(
@@ -135,7 +136,6 @@ fit.model_spec <-
135136
}
136137
check_formula(formula)
137138

138-
139139
if (is_sparse_matrix(data)) {
140140
data <- sparsevctrs::coerce_to_sparse_tibble(data, rlang::caller_env(0))
141141
}
@@ -153,12 +153,14 @@ fit.model_spec <-
153153
eng_vals <- possible_engines(object)
154154
object$engine <- eng_vals[1]
155155
if (control$verbosity > 0) {
156-
cli::cli_warn("Engine set to {.val {object$engine}}.")
156+
cli::cli_warn("Engine set to {.val {object$engine}}.")
157157
}
158158
}
159159

160160
if (all(c("x", "y") %in% names(dots))) {
161-
cli::cli_abort("{.fn fit.model_spec} is for the formula methods. Use {.fn fit_xy} instead.")
161+
cli::cli_abort(
162+
"{.fn fit.model_spec} is for the formula methods. Use {.fn fit_xy} instead."
163+
)
162164
}
163165
cl <- match.call(expand.dots = TRUE)
164166
# Create an environment with the evaluated argument objects. This will be
@@ -186,11 +188,12 @@ fit.model_spec <-
186188
fit_interface <-
187189
check_interface(eval_env$formula, eval_env$data, cl, object)
188190

189-
if (object$engine == "spark" && !inherits(eval_env$data, "tbl_spark"))
191+
if (object$engine == "spark" && !inherits(eval_env$data, "tbl_spark")) {
190192
cli::cli_abort(
191-
"spark objects can only be used with the formula interface to {.fn fit}
193+
"spark objects can only be used with the formula interface to {.fn fit}
192194
with a spark data object."
193-
)
195+
)
196+
}
194197

195198
# populate `method` with the details for this model type
196199
object <- add_methods(object, engine = object$engine)
@@ -208,51 +211,49 @@ fit.model_spec <-
208211
switch(
209212
interfaces,
210213
# homogeneous combinations:
211-
formula_formula =
212-
form_form(
213-
object = object,
214-
control = control,
215-
env = eval_env
216-
),
214+
formula_formula = form_form(
215+
object = object,
216+
control = control,
217+
env = eval_env
218+
),
217219

218220
# heterogenous combinations
219-
formula_matrix =
220-
form_xy(
221-
object = object,
222-
control = control,
223-
env = eval_env,
224-
target = object$method$fit$interface,
225-
...
226-
),
227-
formula_data.frame =
228-
form_xy(
229-
object = object,
230-
control = control,
231-
env = eval_env,
232-
target = object$method$fit$interface,
233-
...
234-
),
221+
formula_matrix = form_xy(
222+
object = object,
223+
control = control,
224+
env = eval_env,
225+
target = object$method$fit$interface,
226+
...
227+
),
228+
formula_data.frame = form_xy(
229+
object = object,
230+
control = control,
231+
env = eval_env,
232+
target = object$method$fit$interface,
233+
...
234+
),
235235

236236
cli::cli_abort("{.val {interfaces}} is unknown.")
237237
)
238238
res$censor_probs <- reverse_km(object, eval_env)
239239
model_classes <- class(res$fit)
240240
class(res) <- c(paste0("_", model_classes[1]), "model_fit")
241241
res
242-
}
242+
}
243243

244244
# ------------------------------------------------------------------------------
245245

246246
#' @rdname fit
247247
#' @export
248248
#' @export fit_xy.model_spec
249249
fit_xy.model_spec <-
250-
function(object,
251-
x,
252-
y,
253-
case_weights = NULL,
254-
control = control_parsnip(),
255-
...
250+
function(
251+
object,
252+
x,
253+
y,
254+
case_weights = NULL,
255+
control = control_parsnip(),
256+
...
256257
) {
257258
if (object$mode == "unknown") {
258259
cli::cli_abort(
@@ -329,32 +330,32 @@ fit_xy.model_spec <-
329330
switch(
330331
interfaces,
331332
# homogeneous combinations:
332-
matrix_matrix = , data.frame_matrix =
333-
xy_xy(
334-
object = object,
335-
env = eval_env,
336-
control = control,
337-
target = "matrix",
338-
...
339-
),
340-
341-
data.frame_data.frame = , matrix_data.frame =
342-
xy_xy(
343-
object = object,
344-
env = eval_env,
345-
control = control,
346-
target = "data.frame",
347-
...
348-
),
333+
matrix_matrix = ,
334+
data.frame_matrix = xy_xy(
335+
object = object,
336+
env = eval_env,
337+
control = control,
338+
target = "matrix",
339+
...
340+
),
341+
342+
data.frame_data.frame = ,
343+
matrix_data.frame = xy_xy(
344+
object = object,
345+
env = eval_env,
346+
control = control,
347+
target = "data.frame",
348+
...
349+
),
349350

350351
# heterogenous combinations
351-
matrix_formula = , data.frame_formula =
352-
xy_form(
353-
object = object,
354-
env = eval_env,
355-
control = control,
356-
...
357-
),
352+
matrix_formula = ,
353+
data.frame_formula = xy_form(
354+
object = object,
355+
env = eval_env,
356+
control = control,
357+
...
358+
),
358359
cli::cli_abort("{.val {interfaces}} is unknown.")
359360
)
360361
res$censor_probs <- reverse_km(object, eval_env)
@@ -368,7 +369,9 @@ fit_xy.model_spec <-
368369
eval_mod <- function(e, capture = FALSE, catch = FALSE, envir = NULL, ...) {
369370
if (capture) {
370371
if (catch) {
371-
junk <- capture.output(res <- try(eval_tidy(e, env = envir, ...), silent = TRUE))
372+
junk <- capture.output(
373+
res <- try(eval_tidy(e, env = envir, ...), silent = TRUE)
374+
)
372375
} else {
373376
junk <- capture.output(res <- eval_tidy(e, env = envir, ...))
374377
}
@@ -391,13 +394,13 @@ check_interface <- function(formula, data, cl, model, call = caller_env()) {
391394
# Determine the `fit()` interface
392395
form_interface <- !is.null(formula) & !is.null(data)
393396

394-
if (form_interface)
397+
if (form_interface) {
395398
return("formula")
399+
}
396400
cli::cli_abort("Error when checking the interface.", call = call)
397401
}
398402

399403
check_xy_interface <- function(x, y, cl, model, call = caller_env()) {
400-
401404
sparse_ok <- allow_sparse(model)
402405
sparse_x <- inherits(x, "dgCMatrix")
403406
if (!sparse_ok & sparse_x) {

0 commit comments

Comments
 (0)