[R] Clearer function signatures for S3 methods (#9937)

This commit is contained in:
david-cortes 2023-12-31 03:45:04 +01:00 committed by GitHub
parent e40c4260ed
commit 8b9c98b65b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 23 deletions

View File

@ -340,7 +340,6 @@ dimnames.xgb.DMatrix <- function(x) {
#' Get information of an xgb.DMatrix object #' Get information of an xgb.DMatrix object
#' @param object Object of class \code{xgb.DMatrix} #' @param object Object of class \code{xgb.DMatrix}
#' @param name the name of the information field to get (see details) #' @param name the name of the information field to get (see details)
#' @param ... other parameters
#' #'
#' @details #' @details
#' The \code{name} field can be one of the following: #' The \code{name} field can be one of the following:
@ -372,11 +371,11 @@ dimnames.xgb.DMatrix <- function(x) {
#' stopifnot(all(labels2 == 1-labels)) #' stopifnot(all(labels2 == 1-labels))
#' @rdname getinfo #' @rdname getinfo
#' @export #' @export
getinfo <- function(object, ...) UseMethod("getinfo") getinfo <- function(object, name) UseMethod("getinfo")
#' @rdname getinfo #' @rdname getinfo
#' @export #' @export
getinfo.xgb.DMatrix <- function(object, name, ...) { getinfo.xgb.DMatrix <- function(object, name) {
allowed_int_fields <- 'group' allowed_int_fields <- 'group'
allowed_float_fields <- c( allowed_float_fields <- c(
'label', 'weight', 'base_margin', 'label', 'weight', 'base_margin',
@ -421,7 +420,6 @@ getinfo.xgb.DMatrix <- function(object, name, ...) {
#' @param object Object of class "xgb.DMatrix" #' @param object Object of class "xgb.DMatrix"
#' @param name the name of the field to get #' @param name the name of the field to get
#' @param info the specific field of information to set #' @param info the specific field of information to set
#' @param ... Not used.
#' #'
#' @details #' @details
#' See the documentation for \link{xgb.DMatrix} for possible fields that can be set #' See the documentation for \link{xgb.DMatrix} for possible fields that can be set
@ -445,17 +443,17 @@ getinfo.xgb.DMatrix <- function(object, name, ...) {
#' stopifnot(all.equal(labels2, 1-labels)) #' stopifnot(all.equal(labels2, 1-labels))
#' @rdname setinfo #' @rdname setinfo
#' @export #' @export
setinfo <- function(object, ...) UseMethod("setinfo") setinfo <- function(object, name, info) UseMethod("setinfo")
#' @rdname setinfo #' @rdname setinfo
#' @export #' @export
setinfo.xgb.DMatrix <- function(object, name, info, ...) { setinfo.xgb.DMatrix <- function(object, name, info) {
.internal.setinfo.xgb.DMatrix(object, name, info, ...) .internal.setinfo.xgb.DMatrix(object, name, info)
attr(object, "fields")[[name]] <- TRUE attr(object, "fields")[[name]] <- TRUE
return(TRUE) return(TRUE)
} }
.internal.setinfo.xgb.DMatrix <- function(object, name, info, ...) { .internal.setinfo.xgb.DMatrix <- function(object, name, info) {
if (name == "label") { if (name == "label") {
if (NROW(info) != nrow(object)) if (NROW(info) != nrow(object))
stop("The length of labels must equal to the number of rows in the input data") stop("The length of labels must equal to the number of rows in the input data")
@ -538,7 +536,6 @@ setinfo.xgb.DMatrix <- function(object, name, info, ...) {
#' @param object Object of class "xgb.DMatrix" #' @param object Object of class "xgb.DMatrix"
#' @param idxset a integer vector of indices of rows needed #' @param idxset a integer vector of indices of rows needed
#' @param colset currently not used (columns subsetting is not available) #' @param colset currently not used (columns subsetting is not available)
#' @param ... other parameters (currently not used)
#' #'
#' @examples #' @examples
#' data(agaricus.train, package='xgboost') #' data(agaricus.train, package='xgboost')
@ -552,11 +549,11 @@ setinfo.xgb.DMatrix <- function(object, name, info, ...) {
#' #'
#' @rdname slice.xgb.DMatrix #' @rdname slice.xgb.DMatrix
#' @export #' @export
slice <- function(object, ...) UseMethod("slice") slice <- function(object, idxset) UseMethod("slice")
#' @rdname slice.xgb.DMatrix #' @rdname slice.xgb.DMatrix
#' @export #' @export
slice.xgb.DMatrix <- function(object, idxset, ...) { 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")
} }

View File

@ -5,15 +5,13 @@
\alias{getinfo.xgb.DMatrix} \alias{getinfo.xgb.DMatrix}
\title{Get information of an xgb.DMatrix object} \title{Get information of an xgb.DMatrix object}
\usage{ \usage{
getinfo(object, ...) getinfo(object, name)
\method{getinfo}{xgb.DMatrix}(object, name, ...) \method{getinfo}{xgb.DMatrix}(object, name)
} }
\arguments{ \arguments{
\item{object}{Object of class \code{xgb.DMatrix}} \item{object}{Object of class \code{xgb.DMatrix}}
\item{...}{other parameters}
\item{name}{the name of the information field to get (see details)} \item{name}{the name of the information field to get (see details)}
} }
\description{ \description{

View File

@ -5,15 +5,13 @@
\alias{setinfo.xgb.DMatrix} \alias{setinfo.xgb.DMatrix}
\title{Set information of an xgb.DMatrix object} \title{Set information of an xgb.DMatrix object}
\usage{ \usage{
setinfo(object, ...) setinfo(object, name, info)
\method{setinfo}{xgb.DMatrix}(object, name, info, ...) \method{setinfo}{xgb.DMatrix}(object, name, info)
} }
\arguments{ \arguments{
\item{object}{Object of class "xgb.DMatrix"} \item{object}{Object of class "xgb.DMatrix"}
\item{...}{Not used.}
\item{name}{the name of the field to get} \item{name}{the name of the field to get}
\item{info}{the specific field of information to set} \item{info}{the specific field of information to set}

View File

@ -7,17 +7,15 @@
\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, ...) slice(object, idxset)
\method{slice}{xgb.DMatrix}(object, idxset, ...) \method{slice}{xgb.DMatrix}(object, idxset)
\method{[}{xgb.DMatrix}(object, idxset, colset = NULL) \method{[}{xgb.DMatrix}(object, idxset, colset = NULL)
} }
\arguments{ \arguments{
\item{object}{Object of class "xgb.DMatrix"} \item{object}{Object of class "xgb.DMatrix"}
\item{...}{other parameters (currently not used)}
\item{idxset}{a integer vector of indices of rows needed} \item{idxset}{a integer vector of indices of rows needed}
\item{colset}{currently not used (columns subsetting is not available)} \item{colset}{currently not used (columns subsetting is not available)}