From 41227d193359d13efee32c94ae5a314d03615f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Benesty?= Date: Thu, 22 Aug 2019 03:42:37 +0200 Subject: [PATCH] fix #4764 (#4800) check all classes in xgb.get.handle --- R-package/R/xgb.Booster.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/R-package/R/xgb.Booster.R b/R-package/R/xgb.Booster.R index 6904219b5..3fc232edf 100644 --- a/R-package/R/xgb.Booster.R +++ b/R-package/R/xgb.Booster.R @@ -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") }