check all classes in xgb.get.handle
This commit is contained in:
Michaël Benesty 2019-08-22 03:42:37 +02:00 committed by Tong He
parent 6e6216ad67
commit 41227d1933

View File

@ -51,11 +51,13 @@ is.null.handle <- function(handle) {
# Return a verified to be valid handle out of either xgb.Booster.handle or xgb.Booster
# internal utility function
xgb.get.handle <- function(object) {
handle <- switch(class(object)[1],
xgb.Booster = object$handle,
xgb.Booster.handle = object,
if (inherits(object, "xgb.Booster")) {
handle <- object$handle
} else if (inherits(object, "xgb.Booster.handle")) {
handle <- object
} else {
stop("argument must be of either xgb.Booster or xgb.Booster.handle class")
)
}
if (is.null.handle(handle)) {
stop("invalid xgb.Booster.handle")
}