diff --git a/R-package/NAMESPACE b/R-package/NAMESPACE index 49f93bb57274..bb5959eab247 100644 --- a/R-package/NAMESPACE +++ b/R-package/NAMESPACE @@ -15,7 +15,6 @@ S3method(print,xgb.DMatrix) S3method(print,xgb.cv.synchronous) S3method(setinfo,xgb.Booster) S3method(setinfo,xgb.DMatrix) -S3method(slice,xgb.DMatrix) S3method(variable.names,xgb.Booster) export("xgb.attr<-") export("xgb.attributes<-") @@ -30,7 +29,6 @@ export(cb.reset.parameters) export(cb.save.model) export(getinfo) export(setinfo) -export(slice) export(xgb.DMatrix) export(xgb.DMatrix.hasinfo) export(xgb.DMatrix.save) @@ -70,6 +68,7 @@ export(xgb.save) export(xgb.save.raw) export(xgb.set.config) export(xgb.slice.Booster) +export(xgb.slice.DMatrix) export(xgb.train) export(xgboost) import(methods) diff --git a/R-package/R/xgb.DMatrix.R b/R-package/R/xgb.DMatrix.R index da036b952b83..fa3340982318 100644 --- a/R-package/R/xgb.DMatrix.R +++ b/R-package/R/xgb.DMatrix.R @@ -1256,19 +1256,15 @@ xgb.get.DMatrix.data <- function(dmat) { #' data(agaricus.train, package='xgboost') #' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label, nthread = 2)) #' -#' dsub <- slice(dtrain, 1:42) +#' dsub <- xgb.slice.DMatrix(dtrain, 1:42) #' labels1 <- getinfo(dsub, 'label') #' dsub <- dtrain[1:42, ] #' labels2 <- getinfo(dsub, 'label') #' all.equal(labels1, labels2) #' -#' @rdname slice.xgb.DMatrix +#' @rdname xgb.slice.DMatrix #' @export -slice <- function(object, idxset) UseMethod("slice") - -#' @rdname slice.xgb.DMatrix -#' @export -slice.xgb.DMatrix <- function(object, idxset) { +xgb.slice.DMatrix <- function(object, idxset) { if (!inherits(object, "xgb.DMatrix")) { stop("object must be xgb.DMatrix") } @@ -1292,10 +1288,10 @@ slice.xgb.DMatrix <- function(object, idxset) { return(structure(ret, class = "xgb.DMatrix")) } -#' @rdname slice.xgb.DMatrix +#' @rdname xgb.slice.DMatrix #' @export `[.xgb.DMatrix` <- function(object, idxset, colset = NULL) { - slice(object, idxset) + xgb.slice.DMatrix(object, idxset) } diff --git a/R-package/R/xgb.cv.R b/R-package/R/xgb.cv.R index eb0495631d6e..29bddb57f3e2 100644 --- a/R-package/R/xgb.cv.R +++ b/R-package/R/xgb.cv.R @@ -197,12 +197,12 @@ xgb.cv <- function(params = list(), data, nrounds, nfold, label = NULL, missing nthread = params$nthread ) bst_folds <- lapply(seq_along(folds), function(k) { - dtest <- slice(dall, folds[[k]]) + dtest <- xgb.slice.DMatrix(dall, folds[[k]]) # code originally contributed by @RolandASc on stackoverflow if (is.null(train_folds)) - dtrain <- slice(dall, unlist(folds[-k])) + dtrain <- xgb.slice.DMatrix(dall, unlist(folds[-k])) else - dtrain <- slice(dall, train_folds[[k]]) + dtrain <- xgb.slice.DMatrix(dall, train_folds[[k]]) bst <- xgb.Booster( params = params, cachelist = list(dtrain, dtest), diff --git a/R-package/man/slice.xgb.DMatrix.Rd b/R-package/man/xgb.slice.DMatrix.Rd similarity index 84% rename from R-package/man/slice.xgb.DMatrix.Rd rename to R-package/man/xgb.slice.DMatrix.Rd index a2dfb699bb0f..c9695996b66f 100644 --- a/R-package/man/slice.xgb.DMatrix.Rd +++ b/R-package/man/xgb.slice.DMatrix.Rd @@ -1,15 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/xgb.DMatrix.R -\name{slice} -\alias{slice} -\alias{slice.xgb.DMatrix} +\name{xgb.slice.DMatrix} +\alias{xgb.slice.DMatrix} \alias{[.xgb.DMatrix} \title{Get a new DMatrix containing the specified rows of original xgb.DMatrix object} \usage{ -slice(object, idxset) - -\method{slice}{xgb.DMatrix}(object, idxset) +xgb.slice.DMatrix(object, idxset) \method{[}{xgb.DMatrix}(object, idxset, colset = NULL) } @@ -28,7 +25,7 @@ original xgb.DMatrix object data(agaricus.train, package='xgboost') dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label, nthread = 2)) -dsub <- slice(dtrain, 1:42) +dsub <- xgb.slice.DMatrix(dtrain, 1:42) labels1 <- getinfo(dsub, 'label') dsub <- dtrain[1:42, ] labels2 <- getinfo(dsub, 'label') diff --git a/R-package/tests/testthat/test_dmatrix.R b/R-package/tests/testthat/test_dmatrix.R index 65374240df00..452b6060620c 100644 --- a/R-package/tests/testthat/test_dmatrix.R +++ b/R-package/tests/testthat/test_dmatrix.R @@ -166,7 +166,7 @@ test_that("xgb.DMatrix: getinfo & setinfo", { test_that("xgb.DMatrix: slice, dim", { dtest <- xgb.DMatrix(test_data, label = test_label, nthread = n_threads) expect_equal(dim(dtest), dim(test_data)) - dsub1 <- slice(dtest, 1:42) + dsub1 <- xgb.slice.DMatrix(dtest, 1:42) expect_equal(nrow(dsub1), 42) expect_equal(ncol(dsub1), ncol(test_data)) @@ -182,12 +182,12 @@ test_that("xgb.DMatrix: slice, trailing empty rows", { dtrain <- xgb.DMatrix( data = train_data, label = train_label, nthread = n_threads ) - slice(dtrain, 6513L) + xgb.slice.DMatrix(dtrain, 6513L) train_data[6513, ] <- 0 dtrain <- xgb.DMatrix( data = train_data, label = train_label, nthread = n_threads ) - slice(dtrain, 6513L) + xgb.slice.DMatrix(dtrain, 6513L) expect_equal(nrow(dtrain), 6513) })