diff --git a/R-package/DESCRIPTION b/R-package/DESCRIPTION index 6fbeeee859be..75f7b938cb29 100755 --- a/R-package/DESCRIPTION +++ b/R-package/DESCRIPTION @@ -63,4 +63,4 @@ Imports: utils SystemRequirements: ~~CXXSTD~~ -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 diff --git a/R-package/NAMESPACE b/R-package/NAMESPACE index 718f0e55a0d7..1f6ed248811c 100644 --- a/R-package/NAMESPACE +++ b/R-package/NAMESPACE @@ -7,7 +7,6 @@ S3method(get_field,lgb.Dataset) S3method(predict,lgb.Booster) S3method(print,lgb.Booster) S3method(set_field,lgb.Dataset) -S3method(slice,lgb.Dataset) S3method(summary,lgb.Booster) export(getLGBMthreads) export(get_field) @@ -32,11 +31,11 @@ export(lgb.plot.importance) export(lgb.plot.interpretation) export(lgb.restore_handle) export(lgb.save) +export(lgb.slice.Dataset) export(lgb.train) export(lightgbm) export(setLGBMthreads) export(set_field) -export(slice) import(methods) importClassesFrom(Matrix,CsparseMatrix) importClassesFrom(Matrix,RsparseMatrix) diff --git a/R-package/R/lgb.Dataset.R b/R-package/R/lgb.Dataset.R index ff9b0b4fa38a..98b9505120de 100644 --- a/R-package/R/lgb.Dataset.R +++ b/R-package/R/lgb.Dataset.R @@ -1061,21 +1061,15 @@ dimnames.lgb.Dataset <- function(x) { #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) #' -#' dsub <- lightgbm::slice(dtrain, seq_len(42L)) +#' dsub <- lgb.slice.Dataset(dtrain, seq_len(42L)) #' lgb.Dataset.construct(dsub) #' labels <- lightgbm::get_field(dsub, "label") #' } #' @export -slice <- function(dataset, idxset) { - UseMethod("slice") -} - -#' @rdname slice -#' @export -slice.lgb.Dataset <- function(dataset, idxset) { +lgb.slice.Dataset <- function(dataset, idxset) { if (!.is_Dataset(x = dataset)) { - stop("slice.lgb.Dataset: input dataset should be an lgb.Dataset object") + stop("lgb.slice.Dataset: input dataset should be an lgb.Dataset object") } return(invisible(dataset$slice(idxset = idxset))) diff --git a/R-package/R/lgb.cv.R b/R-package/R/lgb.cv.R index 0545fbf71899..13685e7f2204 100644 --- a/R-package/R/lgb.cv.R +++ b/R-package/R/lgb.cv.R @@ -327,7 +327,7 @@ lgb.cv <- function(params = list() , init_score = get_field(dataset = data, field_name = "init_score")[test_indices] ) data.table::setorderv(x = indexDT, cols = "indices", order = 1L) - dtest <- slice(data, indexDT$indices) + dtest <- lgb.slice.Dataset(data, indexDT$indices) set_field(dataset = dtest, field_name = "weight", data = indexDT$weight) set_field(dataset = dtest, field_name = "init_score", data = indexDT$init_score) @@ -338,7 +338,7 @@ lgb.cv <- function(params = list() , init_score = get_field(dataset = data, field_name = "init_score")[train_indices] ) data.table::setorderv(x = indexDT, cols = "indices", order = 1L) - dtrain <- slice(data, indexDT$indices) + dtrain <- lgb.slice.Dataset(data, indexDT$indices) set_field(dataset = dtrain, field_name = "weight", data = indexDT$weight) set_field(dataset = dtrain, field_name = "init_score", data = indexDT$init_score) diff --git a/R-package/man/slice.Rd b/R-package/man/lgb.slice.Dataset.Rd similarity index 80% rename from R-package/man/slice.Rd rename to R-package/man/lgb.slice.Dataset.Rd index a65809a239d8..f2a47bcb1885 100644 --- a/R-package/man/slice.Rd +++ b/R-package/man/lgb.slice.Dataset.Rd @@ -1,13 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/lgb.Dataset.R -\name{slice} -\alias{slice} -\alias{slice.lgb.Dataset} +\name{lgb.slice.Dataset} +\alias{lgb.slice.Dataset} \title{Slice a dataset} \usage{ -slice(dataset, idxset) - -\method{slice}{lgb.Dataset}(dataset, idxset) +lgb.slice.Dataset(dataset, idxset) } \arguments{ \item{dataset}{Object of class \code{lgb.Dataset}} @@ -29,7 +26,7 @@ data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) -dsub <- lightgbm::slice(dtrain, seq_len(42L)) +dsub <- lgb.slice.Dataset(dtrain, seq_len(42L)) lgb.Dataset.construct(dsub) labels <- lightgbm::get_field(dsub, "label") } diff --git a/R-package/tests/testthat/test_dataset.R b/R-package/tests/testthat/test_dataset.R index a8585baa2621..65255a730017 100644 --- a/R-package/tests/testthat/test_dataset.R +++ b/R-package/tests/testthat/test_dataset.R @@ -53,7 +53,7 @@ test_that("lgb.Dataset: slice, dim", { dtest <- lgb.Dataset(test_data, label = test_label) lgb.Dataset.construct(dtest) expect_equal(dim(dtest), dim(test_data)) - dsub1 <- slice(dtest, seq_len(42L)) + dsub1 <- lgb.slice.Dataset(dtest, seq_len(42L)) lgb.Dataset.construct(dsub1) expect_equal(nrow(dsub1), 42L) expect_equal(ncol(dsub1), ncol(test_data))