Closed
Description
In get_model_env()
we document the original parameter names of the underlying engine
> parsnip::get_model_env()$decision_tree_args
# A tibble: 6 x 5
engine parsnip original func has_submodel
<chr> <chr> <chr> <list> <lgl>
1 rpart tree_depth maxdepth <named list [2]> FALSE
2 rpart min_n minsplit <named list [2]> FALSE
3 rpart cost_complexity cp <named list [2]> FALSE
4 C5.0 min_n minCases <named list [2]> FALSE
5 spark tree_depth max_depth <named list [2]> FALSE
6 spark min_n min_instances_per_node <named list [2]> FALSE
but we don't say anything about the default values of those parameters.
If we record the function that those original parameters go along with, we could have a function that does a dynamic lookup like this:
lookup_default <- function(fn, arg) {
arg_list <- formals(fn)
has_arg <- arg %in% names(arg_list)
if (!has_arg) {
stop("Argument: `", arg, "` does not exist in the function.", call. = FALSE)
}
default_value <- formals(fn)[[arg]]
default_value
}
lookup_default(rpart::rpart.control, "cp")
#> [1] 0.01
lookup_default(rpart::rpart.control, "cp_oops")
#> Error: Argument: `cp_oops` does not exist in the function.
It would be nice to expose this information to users in the form of a tibble like parsnip::get_model_env()$decision_tree_args
that also has columns for the function that the original parameters come from, and the default values.