Skip to content

Commit 408bedc

Browse files
committed
New function check_spec_pred_type to check that a pred type is available
1 parent 61d8013 commit 408bedc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

R/aaa_models.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,25 @@ check_pred_info <- function(pred_obj, type) {
280280
invisible(NULL)
281281
}
282282

283+
check_spec_pred_type <- function(object, type) {
284+
possible_preds <- names(object$spec$method$pred)
285+
if (!any(possible_preds == type))
286+
rlang::abort(c(
287+
glue::glue("No {type} prediction method available for this model."),
288+
glue::glue("Value for `type` should be one of: ",
289+
glue::glue_collapse(glue::glue("'{possible_preds}'"), sep = ", "))
290+
))
291+
invisible(NULL)
292+
}
293+
294+
283295
check_pkg_val <- function(pkg) {
284296
if (rlang::is_missing(pkg) || length(pkg) != 1 || !is.character(pkg))
285297
rlang::abort("Please supply a single character value for the package name.")
286298
invisible(NULL)
287299
}
288300

301+
289302
check_interface_val <- function(x) {
290303
exp_interf <- c("data.frame", "formula", "matrix")
291304
if (length(x) != 1 || !(x %in% exp_interf)) {

0 commit comments

Comments
 (0)