[R] rename slice to avoid dplyr conflict (#10017)
This commit is contained in:
parent
df7cf744b4
commit
5e00a71671
@ -15,7 +15,6 @@ S3method(print,xgb.DMatrix)
|
|||||||
S3method(print,xgb.cv.synchronous)
|
S3method(print,xgb.cv.synchronous)
|
||||||
S3method(setinfo,xgb.Booster)
|
S3method(setinfo,xgb.Booster)
|
||||||
S3method(setinfo,xgb.DMatrix)
|
S3method(setinfo,xgb.DMatrix)
|
||||||
S3method(slice,xgb.DMatrix)
|
|
||||||
S3method(variable.names,xgb.Booster)
|
S3method(variable.names,xgb.Booster)
|
||||||
export("xgb.attr<-")
|
export("xgb.attr<-")
|
||||||
export("xgb.attributes<-")
|
export("xgb.attributes<-")
|
||||||
@ -30,7 +29,6 @@ export(cb.reset.parameters)
|
|||||||
export(cb.save.model)
|
export(cb.save.model)
|
||||||
export(getinfo)
|
export(getinfo)
|
||||||
export(setinfo)
|
export(setinfo)
|
||||||
export(slice)
|
|
||||||
export(xgb.DMatrix)
|
export(xgb.DMatrix)
|
||||||
export(xgb.DMatrix.hasinfo)
|
export(xgb.DMatrix.hasinfo)
|
||||||
export(xgb.DMatrix.save)
|
export(xgb.DMatrix.save)
|
||||||
@ -70,6 +68,7 @@ export(xgb.save)
|
|||||||
export(xgb.save.raw)
|
export(xgb.save.raw)
|
||||||
export(xgb.set.config)
|
export(xgb.set.config)
|
||||||
export(xgb.slice.Booster)
|
export(xgb.slice.Booster)
|
||||||
|
export(xgb.slice.DMatrix)
|
||||||
export(xgb.train)
|
export(xgb.train)
|
||||||
export(xgboost)
|
export(xgboost)
|
||||||
import(methods)
|
import(methods)
|
||||||
|
|||||||
@ -1228,19 +1228,15 @@ xgb.get.DMatrix.data <- function(dmat) {
|
|||||||
#' data(agaricus.train, package='xgboost')
|
#' data(agaricus.train, package='xgboost')
|
||||||
#' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label, nthread = 2))
|
#' 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')
|
#' labels1 <- getinfo(dsub, 'label')
|
||||||
#' dsub <- dtrain[1:42, ]
|
#' dsub <- dtrain[1:42, ]
|
||||||
#' labels2 <- getinfo(dsub, 'label')
|
#' labels2 <- getinfo(dsub, 'label')
|
||||||
#' all.equal(labels1, labels2)
|
#' all.equal(labels1, labels2)
|
||||||
#'
|
#'
|
||||||
#' @rdname slice.xgb.DMatrix
|
#' @rdname xgb.slice.DMatrix
|
||||||
#' @export
|
#' @export
|
||||||
slice <- function(object, idxset) UseMethod("slice")
|
xgb.slice.DMatrix <- function(object, idxset) {
|
||||||
|
|
||||||
#' @rdname slice.xgb.DMatrix
|
|
||||||
#' @export
|
|
||||||
slice.xgb.DMatrix <- function(object, idxset) {
|
|
||||||
if (!inherits(object, "xgb.DMatrix")) {
|
if (!inherits(object, "xgb.DMatrix")) {
|
||||||
stop("object must be xgb.DMatrix")
|
stop("object must be xgb.DMatrix")
|
||||||
}
|
}
|
||||||
@ -1264,10 +1260,10 @@ slice.xgb.DMatrix <- function(object, idxset) {
|
|||||||
return(structure(ret, class = "xgb.DMatrix"))
|
return(structure(ret, class = "xgb.DMatrix"))
|
||||||
}
|
}
|
||||||
|
|
||||||
#' @rdname slice.xgb.DMatrix
|
#' @rdname xgb.slice.DMatrix
|
||||||
#' @export
|
#' @export
|
||||||
`[.xgb.DMatrix` <- function(object, idxset, colset = NULL) {
|
`[.xgb.DMatrix` <- function(object, idxset, colset = NULL) {
|
||||||
slice(object, idxset)
|
xgb.slice.DMatrix(object, idxset)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -197,12 +197,12 @@ xgb.cv <- function(params = list(), data, nrounds, nfold, label = NULL, missing
|
|||||||
nthread = params$nthread
|
nthread = params$nthread
|
||||||
)
|
)
|
||||||
bst_folds <- lapply(seq_along(folds), function(k) {
|
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
|
# code originally contributed by @RolandASc on stackoverflow
|
||||||
if (is.null(train_folds))
|
if (is.null(train_folds))
|
||||||
dtrain <- slice(dall, unlist(folds[-k]))
|
dtrain <- xgb.slice.DMatrix(dall, unlist(folds[-k]))
|
||||||
else
|
else
|
||||||
dtrain <- slice(dall, train_folds[[k]])
|
dtrain <- xgb.slice.DMatrix(dall, train_folds[[k]])
|
||||||
bst <- xgb.Booster(
|
bst <- xgb.Booster(
|
||||||
params = params,
|
params = params,
|
||||||
cachelist = list(dtrain, dtest),
|
cachelist = list(dtrain, dtest),
|
||||||
|
|||||||
@ -1,15 +1,12 @@
|
|||||||
% Generated by roxygen2: do not edit by hand
|
% Generated by roxygen2: do not edit by hand
|
||||||
% Please edit documentation in R/xgb.DMatrix.R
|
% Please edit documentation in R/xgb.DMatrix.R
|
||||||
\name{slice}
|
\name{xgb.slice.DMatrix}
|
||||||
\alias{slice}
|
\alias{xgb.slice.DMatrix}
|
||||||
\alias{slice.xgb.DMatrix}
|
|
||||||
\alias{[.xgb.DMatrix}
|
\alias{[.xgb.DMatrix}
|
||||||
\title{Get a new DMatrix containing the specified rows of
|
\title{Get a new DMatrix containing the specified rows of
|
||||||
original xgb.DMatrix object}
|
original xgb.DMatrix object}
|
||||||
\usage{
|
\usage{
|
||||||
slice(object, idxset)
|
xgb.slice.DMatrix(object, idxset)
|
||||||
|
|
||||||
\method{slice}{xgb.DMatrix}(object, idxset)
|
|
||||||
|
|
||||||
\method{[}{xgb.DMatrix}(object, idxset, colset = NULL)
|
\method{[}{xgb.DMatrix}(object, idxset, colset = NULL)
|
||||||
}
|
}
|
||||||
@ -28,7 +25,7 @@ original xgb.DMatrix object
|
|||||||
data(agaricus.train, package='xgboost')
|
data(agaricus.train, package='xgboost')
|
||||||
dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label, nthread = 2))
|
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')
|
labels1 <- getinfo(dsub, 'label')
|
||||||
dsub <- dtrain[1:42, ]
|
dsub <- dtrain[1:42, ]
|
||||||
labels2 <- getinfo(dsub, 'label')
|
labels2 <- getinfo(dsub, 'label')
|
||||||
@ -166,7 +166,7 @@ test_that("xgb.DMatrix: getinfo & setinfo", {
|
|||||||
test_that("xgb.DMatrix: slice, dim", {
|
test_that("xgb.DMatrix: slice, dim", {
|
||||||
dtest <- xgb.DMatrix(test_data, label = test_label, nthread = n_threads)
|
dtest <- xgb.DMatrix(test_data, label = test_label, nthread = n_threads)
|
||||||
expect_equal(dim(dtest), dim(test_data))
|
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(nrow(dsub1), 42)
|
||||||
expect_equal(ncol(dsub1), ncol(test_data))
|
expect_equal(ncol(dsub1), ncol(test_data))
|
||||||
|
|
||||||
@ -182,12 +182,12 @@ test_that("xgb.DMatrix: slice, trailing empty rows", {
|
|||||||
dtrain <- xgb.DMatrix(
|
dtrain <- xgb.DMatrix(
|
||||||
data = train_data, label = train_label, nthread = n_threads
|
data = train_data, label = train_label, nthread = n_threads
|
||||||
)
|
)
|
||||||
slice(dtrain, 6513L)
|
xgb.slice.DMatrix(dtrain, 6513L)
|
||||||
train_data[6513, ] <- 0
|
train_data[6513, ] <- 0
|
||||||
dtrain <- xgb.DMatrix(
|
dtrain <- xgb.DMatrix(
|
||||||
data = train_data, label = train_label, nthread = n_threads
|
data = train_data, label = train_label, nthread = n_threads
|
||||||
)
|
)
|
||||||
slice(dtrain, 6513L)
|
xgb.slice.DMatrix(dtrain, 6513L)
|
||||||
expect_equal(nrow(dtrain), 6513)
|
expect_equal(nrow(dtrain), 6513)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user