[R] Handle UTF-8 paths on Windows (#9448)
This commit is contained in:
parent
c1b2cff874
commit
819098a48f
@ -12,7 +12,7 @@ xgb.Booster.handle <- function(params = list(), cachelist = list(),
|
|||||||
## A filename
|
## A filename
|
||||||
handle <- .Call(XGBoosterCreate_R, cachelist)
|
handle <- .Call(XGBoosterCreate_R, cachelist)
|
||||||
modelfile <- path.expand(modelfile)
|
modelfile <- path.expand(modelfile)
|
||||||
.Call(XGBoosterLoadModel_R, handle, modelfile[1])
|
.Call(XGBoosterLoadModel_R, handle, enc2utf8(modelfile[1]))
|
||||||
class(handle) <- "xgb.Booster.handle"
|
class(handle) <- "xgb.Booster.handle"
|
||||||
if (length(params) > 0) {
|
if (length(params) > 0) {
|
||||||
xgb.parameters(handle) <- params
|
xgb.parameters(handle) <- params
|
||||||
|
|||||||
@ -43,6 +43,6 @@ xgb.save <- function(model, fname) {
|
|||||||
}
|
}
|
||||||
model <- xgb.Booster.complete(model, saveraw = FALSE)
|
model <- xgb.Booster.complete(model, saveraw = FALSE)
|
||||||
fname <- path.expand(fname)
|
fname <- path.expand(fname)
|
||||||
.Call(XGBoosterSaveModel_R, model$handle, fname[1])
|
.Call(XGBoosterSaveModel_R, model$handle, enc2utf8(fname[1]))
|
||||||
return(TRUE)
|
return(TRUE)
|
||||||
}
|
}
|
||||||
|
|||||||
21
R-package/tests/testthat/test_unicode.R
Normal file
21
R-package/tests/testthat/test_unicode.R
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
context("Test Unicode handling")
|
||||||
|
|
||||||
|
data(agaricus.train, package = 'xgboost')
|
||||||
|
data(agaricus.test, package = 'xgboost')
|
||||||
|
train <- agaricus.train
|
||||||
|
test <- agaricus.test
|
||||||
|
set.seed(1994)
|
||||||
|
|
||||||
|
test_that("Can save and load models with Unicode paths", {
|
||||||
|
nrounds <- 2
|
||||||
|
bst <- xgboost(data = train$data, label = train$label, max_depth = 2,
|
||||||
|
eta = 1, nthread = 2, nrounds = nrounds, objective = "binary:logistic",
|
||||||
|
eval_metric = "error")
|
||||||
|
tmpdir <- tempdir()
|
||||||
|
lapply(c("모델.json", "がうる・ぐら.json", "类继承.ubj"), function(x) {
|
||||||
|
path <- file.path(tmpdir, x)
|
||||||
|
xgb.save(bst, path)
|
||||||
|
bst2 <- xgb.load(path)
|
||||||
|
expect_equal(predict(bst, test$data), predict(bst2, test$data))
|
||||||
|
})
|
||||||
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user