From b7cbec4d4bf3e102164f083638d41de0aafa2999 Mon Sep 17 00:00:00 2001 From: Ryota Suzuki Date: Wed, 30 May 2018 03:44:55 +0900 Subject: [PATCH] Fix print.xgb.Booster for R (#3338) * Fix print.xgb.Booster valid_handle should be TRUE when x$handle is NOT null * Update xgb.Booster.R Modify is.null.handle to return TRUE for NULL handle --- R-package/R/xgb.Booster.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/R-package/R/xgb.Booster.R b/R-package/R/xgb.Booster.R index c49b45179..9d728c5c4 100644 --- a/R-package/R/xgb.Booster.R +++ b/R-package/R/xgb.Booster.R @@ -37,11 +37,14 @@ xgb.handleToBooster <- function(handle, raw = NULL) { # Check whether xgb.Booster.handle is null # internal utility function is.null.handle <- function(handle) { + if (is.null(handle)) return(TRUE) + if (!identical(class(handle), "xgb.Booster.handle")) stop("argument type must be xgb.Booster.handle") - if (is.null(handle) || .Call(XGCheckNullPtr_R, handle)) + if (.Call(XGCheckNullPtr_R, handle)) return(TRUE) + return(FALSE) } @@ -537,7 +540,7 @@ xgb.ntree <- function(bst) { print.xgb.Booster <- function(x, verbose = FALSE, ...) { cat('##### xgb.Booster\n') - valid_handle <- is.null.handle(x$handle) + valid_handle <- !is.null.handle(x$handle) if (!valid_handle) cat("Handle is invalid! Suggest using xgb.Booster.complete\n")