diff --git a/R-package/R/utils.R b/R-package/R/utils.R index 3c1ffdd20..7336ed213 100644 --- a/R-package/R/utils.R +++ b/R-package/R/utils.R @@ -77,9 +77,9 @@ xgb.Booster <- function(params = list(), cachelist = list(), modelfile = NULL) { } # convert xgb.Booster.handle to xgb.Booster -xgb.handleToBooster <- function(handle) +xgb.handleToBooster <- function(handle, raw = NULL) { - bst <- list(handle = handle, raw = NULL) + bst <- list(handle = handle, raw = raw) class(bst) <- "xgb.Booster" return(bst) } diff --git a/R-package/R/xgb.load.R b/R-package/R/xgb.load.R index b19345b60..b69a719cf 100644 --- a/R-package/R/xgb.load.R +++ b/R-package/R/xgb.load.R @@ -21,7 +21,12 @@ xgb.load <- function(modelfile) { stop("xgb.load: modelfile cannot be NULL") handle <- xgb.Booster(modelfile = modelfile) - bst <- xgb.handleToBooster(handle) + # re-use modelfile if it is raw so we donot need to serialize + if (typeof(modelfile) == "raw") { + bst <- xgb.handleToBooster(handle, modelfile) + } else { + bst <- xgb.handleToBooster(handle, NULL) + } bst <- xgb.Booster.check(bst) return(bst) }