Skip to content

Commit

Permalink
earlier exit for sparse matrix in fit()
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt committed Sep 6, 2024
1 parent 31506c7 commit 0e37996
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ fit.model_spec <-
cli::cli_abort(msg)
}

if (is_sparse_matrix(data)) {
outcome_names <- all.names(rlang::f_lhs(formula))
outcome_ind <- match(outcome_names, colnames(data))

y <- data[, outcome_ind]
x <- data[, -outcome_ind, drop = TRUE]

return(fit_xy(object, x, y, case_weights, control, ...))
}

dots <- quos(...)

if (length(possible_engines(object)) == 0) {
Expand Down Expand Up @@ -174,16 +184,6 @@ fit.model_spec <-
eval_env$formula <- formula
eval_env$weights <- wts

if (is_sparse_matrix(data)) {
outcome_names <- all.names(rlang::f_lhs(formula))
outcome_ind <- match(outcome_names, colnames(data))

y <- data[, outcome_ind]
x <- data[, -outcome_ind, drop = TRUE]

return(fit_xy(object, x, y, case_weights, control, ...))
}

data <- materialize_sparse_tibble(data, object, "data")

fit_interface <-
Expand Down

0 comments on commit 0e37996

Please sign in to comment.