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
This commit is contained in:
Ryota Suzuki 2018-05-30 03:44:55 +09:00 committed by Philip Hyunsu Cho
parent a510e68dda
commit b7cbec4d4b

View File

@ -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")