Skip to content

Commit b949a4b

Browse files
authored
[R] Work on Roxygen documentation (dmlc#10674)
1 parent 5db0803 commit b949a4b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1174
-993
lines changed

R-package/R/callbacks.R

Lines changed: 329 additions & 268 deletions
Large diffs are not rendered by default.

R-package/R/utils.R

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ xgb.createFolds <- function(y, k) {
410410
#' At this time, some of the parameter names were changed in order to make the code style more uniform.
411411
#' The deprecated parameters would be removed in the next release.
412412
#'
413-
#' To see all the current deprecated and new parameters, check the \code{xgboost:::depr_par_lut} table.
413+
#' To see all the current deprecated and new parameters, check the `xgboost:::depr_par_lut` table.
414414
#'
415415
#' A deprecation warning is shown when any of the deprecated parameters is used in a call.
416416
#' An additional warning is shown when there was a partial match to a deprecated parameter
@@ -419,70 +419,79 @@ xgb.createFolds <- function(y, k) {
419419
#' @name xgboost-deprecated
420420
NULL
421421

422-
#' @title Model Serialization and Compatibility
423-
#' @description
422+
#' Model Serialization and Compatibility
424423
#'
424+
#' @description
425425
#' When it comes to serializing XGBoost models, it's possible to use R serializers such as
426-
#' \link{save} or \link{saveRDS} to serialize an XGBoost R model, but XGBoost also provides
426+
#' [save()] or [saveRDS()] to serialize an XGBoost R model, but XGBoost also provides
427427
#' its own serializers with better compatibility guarantees, which allow loading
428428
#' said models in other language bindings of XGBoost.
429429
#'
430-
#' Note that an `xgb.Booster` object, outside of its core components, might also keep:\itemize{
431-
#' \item Additional model configuration (accessible through \link{xgb.config}),
432-
#' which includes model fitting parameters like `max_depth` and runtime parameters like `nthread`.
433-
#' These are not necessarily useful for prediction/importance/plotting.
434-
#' \item Additional R-specific attributes - e.g. results of callbacks, such as evaluation logs,
435-
#' which are kept as a `data.table` object, accessible through `attributes(model)$evaluation_log`
436-
#' if present.
437-
#' }
430+
#' Note that an `xgb.Booster` object, outside of its core components, might also keep:
431+
#' - Additional model configuration (accessible through [xgb.config()]), which includes
432+
#' model fitting parameters like `max_depth` and runtime parameters like `nthread`.
433+
#' These are not necessarily useful for prediction/importance/plotting.
434+
#' - Additional R specific attributes - e.g. results of callbacks, such as evaluation logs,
435+
#' which are kept as a `data.table` object, accessible through
436+
#' `attributes(model)$evaluation_log` if present.
438437
#'
439438
#' The first one (configurations) does not have the same compatibility guarantees as
440-
#' the model itself, including attributes that are set and accessed through \link{xgb.attributes} - that is, such configuration
441-
#' might be lost after loading the booster in a different XGBoost version, regardless of the
442-
#' serializer that was used. These are saved when using \link{saveRDS}, but will be discarded
443-
#' if loaded into an incompatible XGBoost version. They are not saved when using XGBoost's
444-
#' serializers from its public interface including \link{xgb.save} and \link{xgb.save.raw}.
439+
#' the model itself, including attributes that are set and accessed through
440+
#' [xgb.attributes()] - that is, such configuration might be lost after loading the
441+
#' booster in a different XGBoost version, regardless of the serializer that was used.
442+
#' These are saved when using [saveRDS()], but will be discarded if loaded into an
443+
#' incompatible XGBoost version. They are not saved when using XGBoost's
444+
#' serializers from its public interface including [xgb.save()] and [xgb.save.raw()].
445445
#'
446-
#' The second ones (R attributes) are not part of the standard XGBoost model structure, and thus are
447-
#' not saved when using XGBoost's own serializers. These attributes are only used for informational
448-
#' purposes, such as keeping track of evaluation metrics as the model was fit, or saving the R
449-
#' call that produced the model, but are otherwise not used for prediction / importance / plotting / etc.
446+
#' The second ones (R attributes) are not part of the standard XGBoost model structure,
447+
#' and thus are not saved when using XGBoost's own serializers. These attributes are
448+
#' only used for informational purposes, such as keeping track of evaluation metrics as
449+
#' the model was fit, or saving the R call that produced the model, but are otherwise
450+
#' not used for prediction / importance / plotting / etc.
450451
#' These R attributes are only preserved when using R's serializers.
451452
#'
452-
#' Note that XGBoost models in R starting from version `2.1.0` and onwards, and XGBoost models
453-
#' before version `2.1.0`; have a very different R object structure and are incompatible with
454-
#' each other. Hence, models that were saved with R serializers live `saveRDS` or `save` before
455-
#' version `2.1.0` will not work with latter `xgboost` versions and vice versa. Be aware that
456-
#' the structure of R model objects could in theory change again in the future, so XGBoost's serializers
453+
#' Note that XGBoost models in R starting from version `2.1.0` and onwards, and
454+
#' XGBoost models before version `2.1.0`; have a very different R object structure and
455+
#' are incompatible with each other. Hence, models that were saved with R serializers
456+
#' like [saveRDS()] or [save()] before version `2.1.0` will not work with latter
457+
#' `xgboost` versions and vice versa. Be aware that the structure of R model objects
458+
#' could in theory change again in the future, so XGBoost's serializers
457459
#' should be preferred for long-term storage.
458460
#'
459-
#' Furthermore, note that using the package `qs` for serialization will require version 0.26 or
460-
#' higher of said package, and will have the same compatibility restrictions as R serializers.
461+
#' Furthermore, note that using the package `qs` for serialization will require
462+
#' version 0.26 or higher of said package, and will have the same compatibility
463+
#' restrictions as R serializers.
461464
#'
462465
#' @details
463-
#' Use \code{\link{xgb.save}} to save the XGBoost model as a stand-alone file. You may opt into
466+
#' Use [xgb.save()] to save the XGBoost model as a stand-alone file. You may opt into
464467
#' the JSON format by specifying the JSON extension. To read the model back, use
465-
#' \code{\link{xgb.load}}.
468+
#' [xgb.load()].
466469
#'
467-
#' Use \code{\link{xgb.save.raw}} to save the XGBoost model as a sequence (vector) of raw bytes
470+
#' Use [xgb.save.raw()] to save the XGBoost model as a sequence (vector) of raw bytes
468471
#' in a future-proof manner. Future releases of XGBoost will be able to read the raw bytes and
469-
#' re-construct the corresponding model. To read the model back, use \code{\link{xgb.load.raw}}.
470-
#' The \code{\link{xgb.save.raw}} function is useful if you'd like to persist the XGBoost model
472+
#' re-construct the corresponding model. To read the model back, use [xgb.load.raw()].
473+
#' The [xgb.save.raw()] function is useful if you would like to persist the XGBoost model
471474
#' as part of another R object.
472475
#'
473-
#' Use \link{saveRDS} if you require the R-specific attributes that a booster might have, such
476+
#' Use [saveRDS()] if you require the R-specific attributes that a booster might have, such
474477
#' as evaluation logs, but note that future compatibility of such objects is outside XGBoost's
475478
#' control as it relies on R's serialization format (see e.g. the details section in
476-
#' \link{serialize} and \link{save} from base R).
479+
#' [serialize] and [save()] from base R).
477480
#'
478481
#' For more details and explanation about model persistence and archival, consult the page
479482
#' \url{https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html}.
480483
#'
481484
#' @examples
482-
#' data(agaricus.train, package='xgboost')
483-
#' bst <- xgb.train(data = xgb.DMatrix(agaricus.train$data, label = agaricus.train$label),
484-
#' max_depth = 2, eta = 1, nthread = 2, nrounds = 2,
485-
#' objective = "binary:logistic")
485+
#' data(agaricus.train, package = "xgboost")
486+
#'
487+
#' bst <- xgb.train(
488+
#' data = xgb.DMatrix(agaricus.train$data, label = agaricus.train$label),
489+
#' max_depth = 2,
490+
#' eta = 1,
491+
#' nthread = 2,
492+
#' nrounds = 2,
493+
#' objective = "binary:logistic"
494+
#' )
486495
#'
487496
#' # Save as a stand-alone file; load it with xgb.load()
488497
#' fname <- file.path(tempdir(), "xgb_model.ubj")

0 commit comments

Comments
 (0)