R/classLevels.R

Defines functions levels.train

#' @export
levels.train <- function(x, ...) {
  if (any(names(x) == "levels")) {
    out <- x$levels
    attributes(out) <- NULL
  } else {
    if (x$modelType == "Classification") {
      if (
        !isS4(x$finalModel) && !is.null(get_fit_info(x$finalModel, "obsLevels"))
      ) {
        return(get_fit_info(x$finalModel, "obsLevels"))
      }
      if (is.null(x$modelInfo)) {
        code <- getModelInfo(x$method, regex = FALSE)[[1]]
      } else {
        code <- x$modelInfo
      }
      if (!is.null(code$levels)) {
        checkInstall(code$library)
        for (i in seq(along.with = code$library)) {
          do.call("requireNamespaceQuietStop", list(package = code$library[i]))
        }
        out <- code$levels(x$finalModel, ...)
      } else {
        out <- NULL
      }
    } else {
      out <- NULL
    }
  }
  out
}

Try the caret package in your browser

Any scripts or data that you put into this service are public.

caret documentation built on Nov. 15, 2026, 9:06 a.m.