Update the internal_make_spec_tbl() in order to add an extra class to the parsnip model specification that is a combination of the parsnip engine and the parsnip function.
Currently the output and class output is as follows:
internal_make_spec_tbl <- function(.model_tbl){
# Tidyeval ----
model_tbl <- .model_tbl
# Checks ----
if (!inherits(model_tbl, "tidyaml_base_tbl")){
rlang::abort(
message = "The model tibble must come from the make base tbl function.",
use_cli_format = TRUE
)
}
# Manipulation
model_factor_tbl <- model_tbl %>%
dplyr::mutate(.model_id = dplyr::row_number() |>
forcats::as_factor()) |>
dplyr::select(.model_id, dplyr::everything())
# Make a group split object list
models_list <- model_factor_tbl %>%
dplyr::group_split(.model_id)
# Make the Workflow Object using purrr imap
model_spec <- models_list %>%
purrr::imap(
.f = function(obj, id){
# Pull the model column and then pluck the model
pe <- obj |> dplyr::pull(2) |> purrr::pluck(1)
pm <- obj |> dplyr::pull(3) |> purrr::pluck(1)
pf <- obj |> dplyr::pull(4) |> purrr::pluck(1)
ret <- match.fun(pf)(mode = pm, engine = pe)
# Add parsnip engine and fns as class
class(ret) <- c(
class(ret),
paste0(base::tolower(pe), "_", base::tolower(pf))
)
# Return the result
return(ret)
}
)
# Return
# Make sure to return as a tibble
model_spec_ret <- model_factor_tbl |>
dplyr::mutate(model_spec = model_spec) |>
dplyr::mutate(.model_id = as.integer(.model_id))
return(model_spec_ret)
}
Update the
internal_make_spec_tbl()
in order to add an extra class to the parsnip model specification that is a combination of the parsnip engine and the parsnip function.Currently the output and class output is as follows:
Example: