diff --git a/R-package/NAMESPACE b/R-package/NAMESPACE index ac74b8434..a1d296d80 100644 --- a/R-package/NAMESPACE +++ b/R-package/NAMESPACE @@ -16,6 +16,7 @@ export(xgb.save) export(xgb.save.raw) export(xgb.train) export(xgboost) +exportMethods(nrow) exportMethods(predict) import(methods) importClassesFrom(Matrix,dgCMatrix) @@ -52,4 +53,3 @@ importFrom(stringr,str_match) importFrom(stringr,str_replace) importFrom(stringr,str_split) importFrom(stringr,str_trim) -import(vcd) diff --git a/R-package/R/getinfo.xgb.DMatrix.R b/R-package/R/getinfo.xgb.DMatrix.R index 6e291fe62..26523699a 100644 --- a/R-package/R/getinfo.xgb.DMatrix.R +++ b/R-package/R/getinfo.xgb.DMatrix.R @@ -4,6 +4,15 @@ setClass('xgb.DMatrix') #' #' Get information of an xgb.DMatrix object #' +#' The information can be one of the following: +#' +#' \itemize{ +#' \item \code{label}: label Xgboost learn from ; +#' \item \code{weight}: to do a weight rescale ; +#' \item \code{base_margin}: base margin is the base prediction Xgboost will boost from ; +#' \item \code{nrow}: number of rows of the \code{xgb.DMatrix}. +#' } +#' #' @examples #' data(agaricus.train, package='xgboost') #' train <- agaricus.train @@ -19,7 +28,9 @@ getinfo <- function(object, ...){ UseMethod("getinfo") } -#' @param object Object of class "xgb.DMatrix" + + +#' @param object Object of class \code{xgb.DMatrix} #' @param name the name of the field to get #' @param ... other parameters #' @rdname getinfo diff --git a/R-package/R/nrow.xgb.DMatrix.R b/R-package/R/nrow.xgb.DMatrix.R new file mode 100644 index 000000000..9ea039764 --- /dev/null +++ b/R-package/R/nrow.xgb.DMatrix.R @@ -0,0 +1,19 @@ +setGeneric("nrow") + +#' @title Number of xgb.DMatrix rows +#' @description \code{nrow} return the number of rows present in the \code{xgb.DMatrix}. +#' @param x Object of class \code{xgb.DMatrix} +#' +#' @examples +#' data(agaricus.train, package='xgboost') +#' train <- agaricus.train +#' dtrain <- xgb.DMatrix(train$data, label=train$label) +#' stopifnot(nrow(dtrain) == nrow(train$data)) +#' +#' @export +setMethod("nrow", + signature = "xgb.DMatrix", + definition = function(x) { + xgb.numrow(x) + } +) diff --git a/R-package/R/setinfo.xgb.DMatrix.R b/R-package/R/setinfo.xgb.DMatrix.R index 579d9fbcf..61019d8e2 100644 --- a/R-package/R/setinfo.xgb.DMatrix.R +++ b/R-package/R/setinfo.xgb.DMatrix.R @@ -2,6 +2,15 @@ #' #' Set information of an xgb.DMatrix object #' +#' It can be one of the following: +#' +#' \itemize{ +#' \item \code{label}: label Xgboost learn from ; +#' \item \code{weight}: to do a weight rescale ; +#' \item \code{base_margin}: base margin is the base prediction Xgboost will boost from ; +#' \item \code{group}. +#' } +#' #' @examples #' data(agaricus.train, package='xgboost') #' train <- agaricus.train diff --git a/R-package/R/xgboost.R b/R-package/R/xgboost.R index f20b260c9..1007cb91d 100644 --- a/R-package/R/xgboost.R +++ b/R-package/R/xgboost.R @@ -45,7 +45,7 @@ #' train <- agaricus.train #' test <- agaricus.test #' bst <- xgboost(data = train$data, label = train$label, max.depth = 2, -#' eta = 1, nthread = 2, nround = 2,objective = "binary:logistic") +#' eta = 1, nthread = 2, nround = 2, objective = "binary:logistic") #' pred <- predict(bst, test$data) #' #' @export diff --git a/R-package/man/getinfo.Rd b/R-package/man/getinfo.Rd index 37e0ad0be..618d0d44b 100644 --- a/R-package/man/getinfo.Rd +++ b/R-package/man/getinfo.Rd @@ -11,7 +11,7 @@ getinfo(object, ...) \S4method{getinfo}{xgb.DMatrix}(object, name) } \arguments{ -\item{object}{Object of class "xgb.DMatrix"} +\item{object}{Object of class \code{xgb.DMatrix}} \item{...}{other parameters} @@ -20,6 +20,16 @@ getinfo(object, ...) \description{ Get information of an xgb.DMatrix object } +\details{ +The information can be one of the following: + +\itemize{ + \item \code{label}: label Xgboost learn from ; + \item \code{weight}: to do a weight rescale ; + \item \code{base_margin}: base margin is the base prediction Xgboost will boost from ; + \item \code{nrow}: number of rows of the \code{xgb.DMatrix}. +} +} \examples{ data(agaricus.train, package='xgboost') train <- agaricus.train diff --git a/R-package/man/nrow-xgb.DMatrix-method.Rd b/R-package/man/nrow-xgb.DMatrix-method.Rd new file mode 100644 index 000000000..953e620bf --- /dev/null +++ b/R-package/man/nrow-xgb.DMatrix-method.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/nrow.xgb.DMatrix.R +\docType{methods} +\name{nrow,xgb.DMatrix-method} +\alias{nrow,xgb.DMatrix-method} +\title{Number of xgb.DMatrix rows} +\usage{ +\S4method{nrow}{xgb.DMatrix}(x) +} +\arguments{ +\item{x}{Object of class \code{xgb.DMatrix}} +} +\description{ +\code{nrow} return the number of rows present in the \code{xgb.DMatrix}. +} +\examples{ +data(agaricus.train, package='xgboost') +train <- agaricus.train +dtrain <- xgb.DMatrix(train$data, label=train$label) +stopifnot(nrow(dtrain) == nrow(train$data)) +} + diff --git a/R-package/man/setinfo.Rd b/R-package/man/setinfo.Rd index 4ed262b46..9512f1dfb 100644 --- a/R-package/man/setinfo.Rd +++ b/R-package/man/setinfo.Rd @@ -22,6 +22,16 @@ setinfo(object, ...) \description{ Set information of an xgb.DMatrix object } +\details{ +It can be one of the following: + +\itemize{ + \item \code{label}: label Xgboost learn from ; + \item \code{weight}: to do a weight rescale ; + \item \code{base_margin}: base margin is the base prediction Xgboost will boost from ; + \item \code{group}. +} +} \examples{ data(agaricus.train, package='xgboost') train <- agaricus.train diff --git a/R-package/man/xgboost.Rd b/R-package/man/xgboost.Rd index cb9da74f7..a0ec42a9b 100644 --- a/R-package/man/xgboost.Rd +++ b/R-package/man/xgboost.Rd @@ -59,7 +59,7 @@ data(agaricus.test, package='xgboost') train <- agaricus.train test <- agaricus.test bst <- xgboost(data = train$data, label = train$label, max.depth = 2, - eta = 1, nthread = 2, nround = 2,objective = "binary:logistic") + eta = 1, nthread = 2, nround = 2, objective = "binary:logistic") pred <- predict(bst, test$data) }