Skip to content

Commit a347cd5

Browse files
authored
[backport] [R] Fix CRAN test notes. (dmlc#8428) (dmlc#8440)
- Limit the number of used CPU cores in examples. - Add a note for the constraint. - Bring back the cleanup script.
1 parent 9ff0c08 commit a347cd5

22 files changed

+81
-49
lines changed

.github/workflows/r_tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on: [push, pull_request]
55
env:
66
R_PACKAGES: c('XML', 'data.table', 'ggplot2', 'DiagrammeR', 'Ckmeans.1d.dp', 'vcd', 'testthat', 'lintr', 'knitr', 'rmarkdown', 'e1071', 'cplm', 'devtools', 'float', 'titanic')
77
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
8+
_R_CHECK_EXAMPLE_TIMING_CPU_TO_ELAPSED_THRESHOLD_: 2.5
89

910
permissions:
1011
contents: read # to fetch code (actions/checkout)
@@ -68,6 +69,7 @@ jobs:
6869
- {os: windows-latest, r: 'release', compiler: 'mingw', build: 'cmake'}
6970
env:
7071
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
72+
_R_CHECK_EXAMPLE_TIMING_CPU_TO_ELAPSED_THRESHOLD_: 2.5
7173
RSPM: ${{ matrix.config.rspm }}
7274

7375
steps:
@@ -121,6 +123,10 @@ jobs:
121123
config:
122124
- {r: 'release'}
123125

126+
env:
127+
_R_CHECK_EXAMPLE_TIMING_CPU_TO_ELAPSED_THRESHOLD_: 2.5
128+
MAKE: "make -j$(nproc)"
129+
124130
steps:
125131
- uses: actions/checkout@v2
126132
with:

R-package/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@ Imports:
6666
methods,
6767
data.table (>= 1.9.6),
6868
jsonlite (>= 1.0),
69-
RoxygenNote: 7.1.1
69+
RoxygenNote: 7.2.1
7070
SystemRequirements: GNU make, C++14

R-package/R/callbacks.R

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,11 @@ cb.cv.predict <- function(save_models = FALSE) {
544544
#'
545545
#' @return
546546
#' Results are stored in the \code{coefs} element of the closure.
547-
#' The \code{\link{xgb.gblinear.history}} convenience function provides an easy way to access it.
547+
#' The \code{\link{xgb.gblinear.history}} convenience function provides an easy
548+
#' way to access it.
548549
#' With \code{xgb.train}, it is either a dense of a sparse matrix.
549-
#' While with \code{xgb.cv}, it is a list (an element per each fold) of such matrices.
550+
#' While with \code{xgb.cv}, it is a list (an element per each fold) of such
551+
#' matrices.
550552
#'
551553
#' @seealso
552554
#' \code{\link{callbacks}}, \code{\link{xgb.gblinear.history}}.
@@ -558,7 +560,7 @@ cb.cv.predict <- function(save_models = FALSE) {
558560
#' # without considering the 2nd order interactions:
559561
#' x <- model.matrix(Species ~ .^2, iris)[,-1]
560562
#' colnames(x)
561-
#' dtrain <- xgb.DMatrix(scale(x), label = 1*(iris$Species == "versicolor"))
563+
#' dtrain <- xgb.DMatrix(scale(x), label = 1*(iris$Species == "versicolor"), nthread = 2)
562564
#' param <- list(booster = "gblinear", objective = "reg:logistic", eval_metric = "auc",
563565
#' lambda = 0.0003, alpha = 0.0003, nthread = 2)
564566
#' # For 'shotgun', which is a default linear updater, using high eta values may result in
@@ -583,14 +585,14 @@ cb.cv.predict <- function(save_models = FALSE) {
583585
#'
584586
#' # For xgb.cv:
585587
#' bst <- xgb.cv(param, dtrain, nfold = 5, nrounds = 100, eta = 0.8,
586-
#' callbacks = list(cb.gblinear.history()))
588+
#' callbacks = list(cb.gblinear.history()))
587589
#' # coefficients in the CV fold #3
588590
#' matplot(xgb.gblinear.history(bst)[[3]], type = 'l')
589591
#'
590592
#'
591593
#' #### Multiclass classification:
592594
#' #
593-
#' dtrain <- xgb.DMatrix(scale(x), label = as.numeric(iris$Species) - 1)
595+
#' dtrain <- xgb.DMatrix(scale(x), label = as.numeric(iris$Species) - 1, nthread = 2)
594596
#' param <- list(booster = "gblinear", objective = "multi:softprob", num_class = 3,
595597
#' lambda = 0.0003, alpha = 0.0003, nthread = 2)
596598
#' # For the default linear updater 'shotgun' it sometimes is helpful

R-package/R/xgb.DMatrix.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#'
1919
#' @examples
2020
#' data(agaricus.train, package='xgboost')
21-
#' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label))
21+
#' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label, nthread = 2))
2222
#' xgb.DMatrix.save(dtrain, 'xgb.DMatrix.data')
2323
#' dtrain <- xgb.DMatrix('xgb.DMatrix.data')
2424
#' if (file.exists('xgb.DMatrix.data')) file.remove('xgb.DMatrix.data')
@@ -110,7 +110,7 @@ xgb.get.DMatrix <- function(data, label = NULL, missing = NA, weight = NULL, nth
110110
#' @examples
111111
#' data(agaricus.train, package='xgboost')
112112
#' train <- agaricus.train
113-
#' dtrain <- xgb.DMatrix(train$data, label=train$label)
113+
#' dtrain <- xgb.DMatrix(train$data, label=train$label, nthread = 2)
114114
#'
115115
#' stopifnot(nrow(dtrain) == nrow(train$data))
116116
#' stopifnot(ncol(dtrain) == ncol(train$data))
@@ -138,7 +138,7 @@ dim.xgb.DMatrix <- function(x) {
138138
#' @examples
139139
#' data(agaricus.train, package='xgboost')
140140
#' train <- agaricus.train
141-
#' dtrain <- xgb.DMatrix(train$data, label=train$label)
141+
#' dtrain <- xgb.DMatrix(train$data, label=train$label, nthread = 2)
142142
#' dimnames(dtrain)
143143
#' colnames(dtrain)
144144
#' colnames(dtrain) <- make.names(1:ncol(train$data))
@@ -193,7 +193,7 @@ dimnames.xgb.DMatrix <- function(x) {
193193
#'
194194
#' @examples
195195
#' data(agaricus.train, package='xgboost')
196-
#' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label))
196+
#' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label, nthread = 2))
197197
#'
198198
#' labels <- getinfo(dtrain, 'label')
199199
#' setinfo(dtrain, 'label', 1-labels)
@@ -249,7 +249,7 @@ getinfo.xgb.DMatrix <- function(object, name, ...) {
249249
#'
250250
#' @examples
251251
#' data(agaricus.train, package='xgboost')
252-
#' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label))
252+
#' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label, nthread = 2))
253253
#'
254254
#' labels <- getinfo(dtrain, 'label')
255255
#' setinfo(dtrain, 'label', 1-labels)
@@ -345,7 +345,7 @@ setinfo.xgb.DMatrix <- function(object, name, info, ...) {
345345
#'
346346
#' @examples
347347
#' data(agaricus.train, package='xgboost')
348-
#' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label))
348+
#' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label, nthread = 2))
349349
#'
350350
#' dsub <- slice(dtrain, 1:42)
351351
#' labels1 <- getinfo(dsub, 'label')
@@ -401,7 +401,7 @@ slice.xgb.DMatrix <- function(object, idxset, ...) {
401401
#'
402402
#' @examples
403403
#' data(agaricus.train, package='xgboost')
404-
#' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label))
404+
#' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label, nthread = 2))
405405
#'
406406
#' dtrain
407407
#' print(dtrain, verbose=TRUE)

R-package/R/xgb.DMatrix.save.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#'
88
#' @examples
99
#' data(agaricus.train, package='xgboost')
10-
#' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label))
10+
#' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label, nthread = 2))
1111
#' xgb.DMatrix.save(dtrain, 'xgb.DMatrix.data')
1212
#' dtrain <- xgb.DMatrix('xgb.DMatrix.data')
1313
#' if (file.exists('xgb.DMatrix.data')) file.remove('xgb.DMatrix.data')

R-package/R/xgb.create.features.R

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
#' @examples
4949
#' data(agaricus.train, package='xgboost')
5050
#' data(agaricus.test, package='xgboost')
51-
#' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label))
52-
#' dtest <- with(agaricus.test, xgb.DMatrix(data, label = label))
51+
#' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label, nthread = 2))
52+
#' dtest <- with(agaricus.test, xgb.DMatrix(data, label = label, nthread = 2))
5353
#'
5454
#' param <- list(max_depth=2, eta=1, silent=1, objective='binary:logistic')
5555
#' nrounds = 4
@@ -65,8 +65,12 @@
6565
#' new.features.test <- xgb.create.features(model = bst, agaricus.test$data)
6666
#'
6767
#' # learning with new features
68-
#' new.dtrain <- xgb.DMatrix(data = new.features.train, label = agaricus.train$label)
69-
#' new.dtest <- xgb.DMatrix(data = new.features.test, label = agaricus.test$label)
68+
#' new.dtrain <- xgb.DMatrix(
69+
#' data = new.features.train, label = agaricus.train$label, nthread = 2
70+
#' )
71+
#' new.dtest <- xgb.DMatrix(
72+
#' data = new.features.test, label = agaricus.test$label, nthread = 2
73+
#' )
7074
#' watchlist <- list(train = new.dtrain)
7175
#' bst <- xgb.train(params = param, data = new.dtrain, nrounds = nrounds, nthread = 2)
7276
#'
@@ -79,7 +83,7 @@
7983
#' accuracy.after, "!\n"))
8084
#'
8185
#' @export
82-
xgb.create.features <- function(model, data, ...){
86+
xgb.create.features <- function(model, data, ...) {
8387
check.deprecation(...)
8488
pred_with_leaf <- predict(model, data, predleaf = TRUE)
8589
cols <- lapply(as.data.frame(pred_with_leaf), factor)

R-package/R/xgb.cv.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@
110110
#'
111111
#' @examples
112112
#' data(agaricus.train, package='xgboost')
113-
#' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label))
113+
#' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label, nthread = 2))
114114
#' cv <- xgb.cv(data = dtrain, nrounds = 3, nthread = 2, nfold = 5, metrics = list("rmse","auc"),
115-
#' max_depth = 3, eta = 1, objective = "binary:logistic")
115+
#' max_depth = 3, eta = 1, objective = "binary:logistic")
116116
#' print(cv)
117117
#' print(cv, verbose=TRUE)
118118
#'
@@ -192,7 +192,7 @@ xgb.cv <- function(params=list(), data, nrounds, nfold, label = NULL, missing =
192192

193193
# create the booster-folds
194194
# train_folds
195-
dall <- xgb.get.DMatrix(data, label, missing)
195+
dall <- xgb.get.DMatrix(data, label, missing, nthread = params$nthread)
196196
bst_folds <- lapply(seq_along(folds), function(k) {
197197
dtest <- slice(dall, folds[[k]])
198198
# code originally contributed by @RolandASc on stackoverflow

R-package/R/xgb.train.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@
192192
#' data(agaricus.train, package='xgboost')
193193
#' data(agaricus.test, package='xgboost')
194194
#'
195-
#' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label))
196-
#' dtest <- with(agaricus.test, xgb.DMatrix(data, label = label))
195+
#' dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label, nthread = 2))
196+
#' dtest <- with(agaricus.test, xgb.DMatrix(data, label = label, nthread = 2))
197197
#' watchlist <- list(train = dtrain, eval = dtest)
198198
#'
199199
#' ## A simple xgb.train example:

R-package/man/cb.gblinear.history.Rd

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

R-package/man/dim.xgb.DMatrix.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)