[R] switch to URI reader (#10024)

This commit is contained in:
david-cortes
2024-02-04 22:03:38 +01:00
committed by GitHub
parent f2095f1d5b
commit 4de866211d
6 changed files with 103 additions and 20 deletions

View File

@@ -692,3 +692,20 @@ test_that("xgb.DMatrix: quantile cuts look correct", {
}
)
})
test_that("xgb.DMatrix: can read CSV", {
txt <- paste(
"1,2,3",
"-1,3,2",
sep = "\n"
)
fname <- file.path(tempdir(), "data.csv")
writeChar(txt, fname)
uri <- paste0(fname, "?format=csv&label_column=0")
dm <- xgb.DMatrix(uri, silent = TRUE)
expect_equal(getinfo(dm, "label"), c(1, -1))
expect_equal(
as.matrix(xgb.get.DMatrix.data(dm)),
matrix(c(2, 3, 3, 2), nrow = 2, byrow = TRUE)
)
})