From c454d5f8ccc7e96350719bd6af43b7ecc5288a8a Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 5 Aug 2020 20:53:11 -0500 Subject: [PATCH] [R-package] move all examples to dontrun() to fix R CMD CHECK notes (#3270) * Move all examples to dontrun * update docs * fix nested dontrun * remove :: in examples * run_dontrun in pkgdown Co-authored-by: Nikita Titov --- .ci/test_r_package.sh | 1 + .ci/test_r_package_windows.ps1 | 2 +- R-package/R/lgb.Booster.R | 10 ++++-- R-package/R/lgb.Dataset.R | 32 ++++++++++++++------ R-package/R/lgb.convert.R | 5 ++- R-package/R/lgb.convert_with_rules.R | 3 +- R-package/R/lgb.cv.R | 2 ++ R-package/R/lgb.importance.R | 3 +- R-package/R/lgb.interprete.R | 3 +- R-package/R/lgb.model.dt.tree.R | 4 +-- R-package/R/lgb.plot.importance.R | 2 ++ R-package/R/lgb.plot.interpretation.R | 2 +- R-package/R/lgb.train.R | 2 ++ R-package/R/lgb.unloader.R | 3 +- R-package/R/readRDS.lgb.Booster.R | 2 +- R-package/R/saveRDS.lgb.Booster.R | 2 +- R-package/man/dim.Rd | 3 +- R-package/man/dimnames.lgb.Dataset.Rd | 3 +- R-package/man/getinfo.Rd | 3 +- R-package/man/lgb.Dataset.Rd | 3 +- R-package/man/lgb.Dataset.construct.Rd | 3 +- R-package/man/lgb.Dataset.create.valid.Rd | 3 +- R-package/man/lgb.Dataset.save.Rd | 2 ++ R-package/man/lgb.Dataset.set.categorical.Rd | 3 +- R-package/man/lgb.Dataset.set.reference.Rd | 3 +- R-package/man/lgb.convert.Rd | 5 ++- R-package/man/lgb.convert_with_rules.Rd | 3 +- R-package/man/lgb.cv.Rd | 2 ++ R-package/man/lgb.dump.Rd | 2 +- R-package/man/lgb.get.eval.result.Rd | 2 ++ R-package/man/lgb.importance.Rd | 3 +- R-package/man/lgb.interprete.Rd | 3 +- R-package/man/lgb.load.Rd | 2 +- R-package/man/lgb.model.dt.tree.Rd | 4 +-- R-package/man/lgb.plot.importance.Rd | 2 ++ R-package/man/lgb.plot.interpretation.Rd | 2 +- R-package/man/lgb.save.Rd | 2 +- R-package/man/lgb.train.Rd | 2 ++ R-package/man/lgb.unloader.Rd | 3 +- R-package/man/predict.lgb.Booster.Rd | 2 ++ R-package/man/readRDS.lgb.Booster.Rd | 2 +- R-package/man/saveRDS.lgb.Booster.Rd | 2 +- R-package/man/setinfo.Rd | 3 +- R-package/man/slice.Rd | 3 +- docs/conf.py | 2 +- 45 files changed, 101 insertions(+), 54 deletions(-) diff --git a/.ci/test_r_package.sh b/.ci/test_r_package.sh index a45b3a8278a1..42564f293b44 100755 --- a/.ci/test_r_package.sh +++ b/.ci/test_r_package.sh @@ -173,6 +173,7 @@ check_succeeded="yes" ( R CMD check ${PKG_TARBALL} \ --as-cran \ + --run-dontrun \ || check_succeeded="no" ) & diff --git a/.ci/test_r_package_windows.ps1 b/.ci/test_r_package_windows.ps1 index 3349aac68bd2..ac379f05fdb1 100644 --- a/.ci/test_r_package_windows.ps1 +++ b/.ci/test_r_package_windows.ps1 @@ -160,7 +160,7 @@ if ($env:COMPILER -ne "MSVC") { } Write-Output "Running R CMD check as CRAN" - Run-R-Code-Redirect-Stderr "result <- processx::run(command = 'R.exe', args = c('CMD', 'check', '--no-multiarch', '--as-cran', '$PKG_FILE_NAME'), echo = TRUE, windows_verbatim_args = FALSE)" ; $check_succeeded = $? + Run-R-Code-Redirect-Stderr "result <- processx::run(command = 'R.exe', args = c('CMD', 'check', '--no-multiarch', '--as-cran', '--run-dontrun', '$PKG_FILE_NAME'), echo = TRUE, windows_verbatim_args = FALSE)" ; $check_succeeded = $? Write-Output "R CMD check build logs:" $INSTALL_LOG_FILE_NAME = "lightgbm.Rcheck\00install.out" diff --git a/R-package/R/lgb.Booster.R b/R-package/R/lgb.Booster.R index 8fa4b5af143b..d64e82fd894e 100644 --- a/R-package/R/lgb.Booster.R +++ b/R-package/R/lgb.Booster.R @@ -718,6 +718,7 @@ Booster <- R6::R6Class( #' number of columns corresponding to the number of trees. #' #' @examples +#' \dontrun{ #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) @@ -735,6 +736,7 @@ Booster <- R6::R6Class( #' , learning_rate = 1.0 #' ) #' preds <- predict(model, test$data) +#' } #' @export predict.lgb.Booster <- function(object, data, @@ -774,7 +776,7 @@ predict.lgb.Booster <- function(object, #' @return lgb.Booster #' #' @examples -#' \donttest{ +#' \dontrun{ #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) @@ -834,7 +836,7 @@ lgb.load <- function(filename = NULL, model_str = NULL) { #' @return lgb.Booster #' #' @examples -#' \donttest{ +#' \dontrun{ #' library(lightgbm) #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train @@ -882,7 +884,7 @@ lgb.save <- function(booster, filename, num_iteration = NULL) { #' @return json format of model #' #' @examples -#' \donttest{ +#' \dontrun{ #' library(lightgbm) #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train @@ -930,6 +932,7 @@ lgb.dump <- function(booster, num_iteration = NULL) { #' @return vector of evaluation result #' #' @examples +#' \dontrun{ #' # train a regression model #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train @@ -956,6 +959,7 @@ lgb.dump <- function(booster, num_iteration = NULL) { #' #' # Get L2 values for "test" dataset #' lgb.get.eval.result(model, "test", "l2") +#' } #' @export lgb.get.eval.result <- function(booster, data_name, eval_name, iters = NULL, is_err = FALSE) { diff --git a/R-package/R/lgb.Dataset.R b/R-package/R/lgb.Dataset.R index 88cc60bd6a96..9bfe0af21221 100644 --- a/R-package/R/lgb.Dataset.R +++ b/R-package/R/lgb.Dataset.R @@ -725,6 +725,7 @@ Dataset <- R6::R6Class( #' @return constructed dataset #' #' @examples +#' \dontrun{ #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) @@ -732,7 +733,7 @@ Dataset <- R6::R6Class( #' lgb.Dataset.save(dtrain, data_file) #' dtrain <- lgb.Dataset(data_file) #' lgb.Dataset.construct(dtrain) -#' +#' } #' @export lgb.Dataset <- function(data, params = list(), @@ -770,13 +771,14 @@ lgb.Dataset <- function(data, #' @return constructed dataset #' #' @examples +#' \dontrun{ #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) #' data(agaricus.test, package = "lightgbm") #' test <- agaricus.test #' dtest <- lgb.Dataset.create.valid(dtrain, test$data, label = test$label) -#' +#' } #' @export lgb.Dataset.create.valid <- function(dataset, data, info = list(), ...) { @@ -796,11 +798,12 @@ lgb.Dataset.create.valid <- function(dataset, data, info = list(), ...) { #' @param dataset Object of class \code{lgb.Dataset} #' #' @examples +#' \dontrun{ #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) #' lgb.Dataset.construct(dtrain) -#' +#' } #' @export lgb.Dataset.construct <- function(dataset) { @@ -826,6 +829,7 @@ lgb.Dataset.construct <- function(dataset) { #' be directly used with an \code{lgb.Dataset} object. #' #' @examples +#' \dontrun{ #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) @@ -833,7 +837,7 @@ lgb.Dataset.construct <- function(dataset) { #' stopifnot(nrow(dtrain) == nrow(train$data)) #' stopifnot(ncol(dtrain) == ncol(train$data)) #' stopifnot(all(dim(dtrain) == dim(train$data))) -#' +#' } #' @rdname dim #' @export dim.lgb.Dataset <- function(x, ...) { @@ -860,6 +864,7 @@ dim.lgb.Dataset <- function(x, ...) { #' Since row names are irrelevant, it is recommended to use \code{colnames} directly. #' #' @examples +#' \dontrun{ #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) @@ -868,7 +873,7 @@ dim.lgb.Dataset <- function(x, ...) { #' colnames(dtrain) #' colnames(dtrain) <- make.names(seq_len(ncol(train$data))) #' print(dtrain, verbose = TRUE) -#' +#' } #' @rdname dimnames.lgb.Dataset #' @export dimnames.lgb.Dataset <- function(x) { @@ -932,6 +937,7 @@ dimnames.lgb.Dataset <- function(x) { #' @return constructed sub dataset #' #' @examples +#' \dontrun{ #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) @@ -939,7 +945,7 @@ dimnames.lgb.Dataset <- function(x) { #' dsub <- lightgbm::slice(dtrain, seq_len(42L)) #' lgb.Dataset.construct(dsub) #' labels <- lightgbm::getinfo(dsub, "label") -#' +#' } #' @export slice <- function(dataset, ...) { UseMethod("slice") @@ -978,6 +984,7 @@ slice.lgb.Dataset <- function(dataset, idxset, ...) { #' } #' #' @examples +#' \dontrun{ #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) @@ -988,7 +995,7 @@ slice.lgb.Dataset <- function(dataset, idxset, ...) { #' #' labels2 <- lightgbm::getinfo(dtrain, "label") #' stopifnot(all(labels2 == 1 - labels)) -#' +#' } #' @export getinfo <- function(dataset, ...) { UseMethod("getinfo") @@ -1031,6 +1038,7 @@ getinfo.lgb.Dataset <- function(dataset, name, ...) { #' } #' #' @examples +#' \dontrun{ #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) @@ -1041,7 +1049,7 @@ getinfo.lgb.Dataset <- function(dataset, name, ...) { #' #' labels2 <- lightgbm::getinfo(dtrain, "label") #' stopifnot(all.equal(labels2, 1 - labels)) -#' +#' } #' @export setinfo <- function(dataset, ...) { UseMethod("setinfo") @@ -1071,6 +1079,7 @@ setinfo.lgb.Dataset <- function(dataset, name, info, ...) { #' @return passed dataset #' #' @examples +#' \dontrun{ #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) @@ -1078,7 +1087,7 @@ setinfo.lgb.Dataset <- function(dataset, name, info, ...) { #' lgb.Dataset.save(dtrain, data_file) #' dtrain <- lgb.Dataset(data_file) #' lgb.Dataset.set.categorical(dtrain, 1L:2L) -#' +#' } #' @rdname lgb.Dataset.set.categorical #' @export lgb.Dataset.set.categorical <- function(dataset, categorical_feature) { @@ -1102,6 +1111,7 @@ lgb.Dataset.set.categorical <- function(dataset, categorical_feature) { #' @return passed dataset #' #' @examples +#' \dontrun{ #' data(agaricus.train, package ="lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) @@ -1109,7 +1119,7 @@ lgb.Dataset.set.categorical <- function(dataset, categorical_feature) { #' test <- agaricus.test #' dtest <- lgb.Dataset(test$data, test = train$label) #' lgb.Dataset.set.reference(dtest, dtrain) -#' +#' } #' @rdname lgb.Dataset.set.reference #' @export lgb.Dataset.set.reference <- function(dataset, reference) { @@ -1133,10 +1143,12 @@ lgb.Dataset.set.reference <- function(dataset, reference) { #' @return passed dataset #' #' @examples +#' \dontrun{ #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) #' lgb.Dataset.save(dtrain, tempfile(fileext = ".bin")) +#' } #' @export lgb.Dataset.save <- function(dataset, fname) { diff --git a/R-package/R/lgb.convert.R b/R-package/R/lgb.convert.R index a37ee25d0ba2..a266b3cd33ca 100644 --- a/R-package/R/lgb.convert.R +++ b/R-package/R/lgb.convert.R @@ -12,6 +12,7 @@ #' for input in \code{lgb.Dataset}. #' #' @examples +#' \dontrun{ #' data(iris) #' #' str(iris) @@ -19,11 +20,10 @@ #' # Convert all factors/chars to integer #' str(lgb.convert(data = iris)) #' -#' \dontrun{ #' # When lightgbm package is installed, and you do not want to load it #' # You can still use the function! #' lgb.unloader() -#' str(lightgbm::lgb.convert(data = iris)) +#' str(lgb.convert(data = iris)) #' # 'data.frame': 150 obs. of 5 variables: #' # $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... #' # $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... @@ -31,7 +31,6 @@ #' # $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... #' # $ Species : int 1 1 1 1 1 1 1 1 1 1 ... #' } -#' #' @export lgb.convert <- function(data) { diff --git a/R-package/R/lgb.convert_with_rules.R b/R-package/R/lgb.convert_with_rules.R index 7a902ecbee44..66c5f4461d70 100644 --- a/R-package/R/lgb.convert_with_rules.R +++ b/R-package/R/lgb.convert_with_rules.R @@ -13,6 +13,7 @@ #' \code{lgb.Dataset}. #' #' @examples +#' \dontrun{ #' data(iris) #' #' str(iris) @@ -48,7 +49,7 @@ #' ) #' newest_iris <- lgb.convert_with_rules(data = iris, rules = personal_rules) #' str(newest_iris$data) # SUCCESS! -#' +#' } #' @importFrom data.table set #' @export lgb.convert_with_rules <- function(data, rules = NULL) { diff --git a/R-package/R/lgb.cv.R b/R-package/R/lgb.cv.R index a9a72027347b..4a4157644eb3 100644 --- a/R-package/R/lgb.cv.R +++ b/R-package/R/lgb.cv.R @@ -56,6 +56,7 @@ CVBooster <- R6::R6Class( #' @return a trained model \code{lgb.CVBooster}. #' #' @examples +#' \dontrun{ #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) @@ -68,6 +69,7 @@ CVBooster <- R6::R6Class( #' , min_data = 1L #' , learning_rate = 1.0 #' ) +#' } #' @importFrom data.table data.table setorderv #' @export lgb.cv <- function(params = list() diff --git a/R-package/R/lgb.importance.R b/R-package/R/lgb.importance.R index 3064673f664a..764e11cd5948 100644 --- a/R-package/R/lgb.importance.R +++ b/R-package/R/lgb.importance.R @@ -13,6 +13,7 @@ #' } #' #' @examples +#' \dontrun{ #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) @@ -32,7 +33,7 @@ #' #' tree_imp1 <- lgb.importance(model, percentage = TRUE) #' tree_imp2 <- lgb.importance(model, percentage = FALSE) -#' +#' } #' @importFrom data.table := setnames setorderv #' @export lgb.importance <- function(model, percentage = TRUE) { diff --git a/R-package/R/lgb.interprete.R b/R-package/R/lgb.interprete.R index e97fb1b590a1..1885cf666ae7 100644 --- a/R-package/R/lgb.interprete.R +++ b/R-package/R/lgb.interprete.R @@ -16,6 +16,7 @@ #' Contribution columns to each class. #' #' @examples +#' \dontrun{ #' Logit <- function(x) log(x / (1.0 - x)) #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train @@ -38,7 +39,7 @@ #' ) #' #' tree_interpretation <- lgb.interprete(model, test$data, 1L:5L) -#' +#' } #' @importFrom data.table as.data.table #' @export lgb.interprete <- function(model, diff --git a/R-package/R/lgb.model.dt.tree.R b/R-package/R/lgb.model.dt.tree.R index e6f8b667e63a..436fe5109ff5 100644 --- a/R-package/R/lgb.model.dt.tree.R +++ b/R-package/R/lgb.model.dt.tree.R @@ -28,7 +28,7 @@ #' } #' #' @examples -#' +#' \dontrun{ #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) @@ -44,7 +44,7 @@ #' model <- lgb.train(params, dtrain, 10L) #' #' tree_dt <- lgb.model.dt.tree(model) -#' +#' } #' @importFrom data.table := rbindlist #' @importFrom jsonlite fromJSON #' @export diff --git a/R-package/R/lgb.plot.importance.R b/R-package/R/lgb.plot.importance.R index ec496c4213f3..109c43633320 100644 --- a/R-package/R/lgb.plot.importance.R +++ b/R-package/R/lgb.plot.importance.R @@ -18,6 +18,7 @@ #' and silently returns a processed data.table with \code{top_n} features sorted by defined importance. #' #' @examples +#' \dontrun{ #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) @@ -37,6 +38,7 @@ #' #' tree_imp <- lgb.importance(model, percentage = TRUE) #' lgb.plot.importance(tree_imp, top_n = 5L, measure = "Gain") +#' } #' @importFrom graphics barplot par #' @export lgb.plot.importance <- function(tree_imp, diff --git a/R-package/R/lgb.plot.interpretation.R b/R-package/R/lgb.plot.interpretation.R index 486b80dd46dd..6752edc197a2 100644 --- a/R-package/R/lgb.plot.interpretation.R +++ b/R-package/R/lgb.plot.interpretation.R @@ -15,7 +15,7 @@ #' The \code{lgb.plot.interpretation} function creates a \code{barplot}. #' #' @examples -#' \donttest{ +#' \dontrun{ #' Logit <- function(x) { #' log(x / (1.0 - x)) #' } diff --git a/R-package/R/lgb.train.R b/R-package/R/lgb.train.R index 649e82deefb4..a5f3b8e0e460 100644 --- a/R-package/R/lgb.train.R +++ b/R-package/R/lgb.train.R @@ -29,6 +29,7 @@ #' @return a trained booster model \code{lgb.Booster}. #' #' @examples +#' \dontrun{ #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) @@ -46,6 +47,7 @@ #' , learning_rate = 1.0 #' , early_stopping_rounds = 3L #' ) +#' } #' @export lgb.train <- function(params = list(), data, diff --git a/R-package/R/lgb.unloader.R b/R-package/R/lgb.unloader.R index c08f00226879..a018222d93c2 100644 --- a/R-package/R/lgb.unloader.R +++ b/R-package/R/lgb.unloader.R @@ -14,6 +14,7 @@ #' @return NULL invisibly. #' #' @examples +#' \dontrun{ #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) @@ -31,7 +32,6 @@ #' , learning_rate = 1.0 #' ) #' -#' \dontrun{ #' lgb.unloader(restore = FALSE, wipe = FALSE, envir = .GlobalEnv) #' rm(model, dtrain, dtest) # Not needed if wipe = TRUE #' gc() # Not needed if wipe = TRUE @@ -39,7 +39,6 @@ #' library(lightgbm) #' # Do whatever you want again with LightGBM without object clashing #' } -#' #' @export lgb.unloader <- function(restore = TRUE, wipe = FALSE, envir = .GlobalEnv) { diff --git a/R-package/R/readRDS.lgb.Booster.R b/R-package/R/readRDS.lgb.Booster.R index 23c1afbee4d4..b14e77c2df86 100644 --- a/R-package/R/readRDS.lgb.Booster.R +++ b/R-package/R/readRDS.lgb.Booster.R @@ -7,7 +7,7 @@ #' @return \code{lgb.Booster}. #' #' @examples -#' \donttest{ +#' \dontrun{ #' library(lightgbm) #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train diff --git a/R-package/R/saveRDS.lgb.Booster.R b/R-package/R/saveRDS.lgb.Booster.R index 7a2f838e9ff5..f54e3645d463 100644 --- a/R-package/R/saveRDS.lgb.Booster.R +++ b/R-package/R/saveRDS.lgb.Booster.R @@ -18,7 +18,7 @@ #' @return NULL invisibly. #' #' @examples -#' \donttest{ +#' \dontrun{ #' library(lightgbm) #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train diff --git a/R-package/man/dim.Rd b/R-package/man/dim.Rd index 55fde26d6a5b..5361b5c0c467 100644 --- a/R-package/man/dim.Rd +++ b/R-package/man/dim.Rd @@ -22,6 +22,7 @@ Note: since \code{nrow} and \code{ncol} internally use \code{dim}, they can also be directly used with an \code{lgb.Dataset} object. } \examples{ +\dontrun{ data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) @@ -29,5 +30,5 @@ dtrain <- lgb.Dataset(train$data, label = train$label) stopifnot(nrow(dtrain) == nrow(train$data)) stopifnot(ncol(dtrain) == ncol(train$data)) stopifnot(all(dim(dtrain) == dim(train$data))) - +} } diff --git a/R-package/man/dimnames.lgb.Dataset.Rd b/R-package/man/dimnames.lgb.Dataset.Rd index 22be85149646..5fb3edcefba5 100644 --- a/R-package/man/dimnames.lgb.Dataset.Rd +++ b/R-package/man/dimnames.lgb.Dataset.Rd @@ -24,6 +24,7 @@ Generic \code{dimnames} methods are used by \code{colnames}. Since row names are irrelevant, it is recommended to use \code{colnames} directly. } \examples{ +\dontrun{ data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) @@ -32,5 +33,5 @@ dimnames(dtrain) colnames(dtrain) colnames(dtrain) <- make.names(seq_len(ncol(train$data))) print(dtrain, verbose = TRUE) - +} } diff --git a/R-package/man/getinfo.Rd b/R-package/man/getinfo.Rd index 2925308ed7e9..f12e8b39e871 100644 --- a/R-package/man/getinfo.Rd +++ b/R-package/man/getinfo.Rd @@ -33,6 +33,7 @@ The \code{name} field can be one of the following: } } \examples{ +\dontrun{ data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) @@ -43,5 +44,5 @@ lightgbm::setinfo(dtrain, "label", 1 - labels) labels2 <- lightgbm::getinfo(dtrain, "label") stopifnot(all(labels2 == 1 - labels)) - +} } diff --git a/R-package/man/lgb.Dataset.Rd b/R-package/man/lgb.Dataset.Rd index 52e9b74058ee..771efff6f1db 100644 --- a/R-package/man/lgb.Dataset.Rd +++ b/R-package/man/lgb.Dataset.Rd @@ -40,6 +40,7 @@ Construct \code{lgb.Dataset} object from dense matrix, sparse matrix or local file (that was created previously by saving an \code{lgb.Dataset}). } \examples{ +\dontrun{ data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) @@ -47,5 +48,5 @@ data_file <- tempfile(fileext = ".data") lgb.Dataset.save(dtrain, data_file) dtrain <- lgb.Dataset(data_file) lgb.Dataset.construct(dtrain) - +} } diff --git a/R-package/man/lgb.Dataset.construct.Rd b/R-package/man/lgb.Dataset.construct.Rd index 4338f84b669c..4bceed705773 100644 --- a/R-package/man/lgb.Dataset.construct.Rd +++ b/R-package/man/lgb.Dataset.construct.Rd @@ -13,9 +13,10 @@ lgb.Dataset.construct(dataset) Construct Dataset explicitly } \examples{ +\dontrun{ data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) lgb.Dataset.construct(dtrain) - +} } diff --git a/R-package/man/lgb.Dataset.create.valid.Rd b/R-package/man/lgb.Dataset.create.valid.Rd index 0669f1887171..0c6efcff1f96 100644 --- a/R-package/man/lgb.Dataset.create.valid.Rd +++ b/R-package/man/lgb.Dataset.create.valid.Rd @@ -22,11 +22,12 @@ constructed dataset Construct validation data according to training data } \examples{ +\dontrun{ data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) data(agaricus.test, package = "lightgbm") test <- agaricus.test dtest <- lgb.Dataset.create.valid(dtrain, test$data, label = test$label) - +} } diff --git a/R-package/man/lgb.Dataset.save.Rd b/R-package/man/lgb.Dataset.save.Rd index 699788d39977..fc5f765138bb 100644 --- a/R-package/man/lgb.Dataset.save.Rd +++ b/R-package/man/lgb.Dataset.save.Rd @@ -19,8 +19,10 @@ Please note that \code{init_score} is not saved in binary file. If you need it, please set it again after loading Dataset. } \examples{ +\dontrun{ data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) lgb.Dataset.save(dtrain, tempfile(fileext = ".bin")) } +} diff --git a/R-package/man/lgb.Dataset.set.categorical.Rd b/R-package/man/lgb.Dataset.set.categorical.Rd index debe7e02d151..5b935791b8a1 100644 --- a/R-package/man/lgb.Dataset.set.categorical.Rd +++ b/R-package/man/lgb.Dataset.set.categorical.Rd @@ -21,6 +21,7 @@ Set the categorical features of an \code{lgb.Dataset} object. Use this function to tell LightGBM which features should be treated as categorical. } \examples{ +\dontrun{ data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) @@ -28,5 +29,5 @@ data_file <- tempfile(fileext = ".data") lgb.Dataset.save(dtrain, data_file) dtrain <- lgb.Dataset(data_file) lgb.Dataset.set.categorical(dtrain, 1L:2L) - +} } diff --git a/R-package/man/lgb.Dataset.set.reference.Rd b/R-package/man/lgb.Dataset.set.reference.Rd index e8bd41820286..882254c53456 100644 --- a/R-package/man/lgb.Dataset.set.reference.Rd +++ b/R-package/man/lgb.Dataset.set.reference.Rd @@ -18,6 +18,7 @@ passed dataset If you want to use validation data, you should set reference to training data } \examples{ +\dontrun{ data(agaricus.train, package ="lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) @@ -25,5 +26,5 @@ data(agaricus.test, package = "lightgbm") test <- agaricus.test dtest <- lgb.Dataset(test$data, test = train$label) lgb.Dataset.set.reference(dtest, dtrain) - +} } diff --git a/R-package/man/lgb.convert.Rd b/R-package/man/lgb.convert.Rd index 0fdc3a7d2717..cb67a4dc800a 100644 --- a/R-package/man/lgb.convert.Rd +++ b/R-package/man/lgb.convert.Rd @@ -23,6 +23,7 @@ Attempts to prepare a clean dataset to prepare to put in a \code{lgb.Dataset}. NOTE: In previous releases of LightGBM, this function was called \code{lgb.prepare}. } \examples{ +\dontrun{ data(iris) str(iris) @@ -30,11 +31,10 @@ str(iris) # Convert all factors/chars to integer str(lgb.convert(data = iris)) -\dontrun{ # When lightgbm package is installed, and you do not want to load it # You can still use the function! lgb.unloader() -str(lightgbm::lgb.convert(data = iris)) +str(lgb.convert(data = iris)) # 'data.frame': 150 obs. of 5 variables: # $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... # $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... @@ -42,5 +42,4 @@ str(lightgbm::lgb.convert(data = iris)) # $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... # $ Species : int 1 1 1 1 1 1 1 1 1 1 ... } - } diff --git a/R-package/man/lgb.convert_with_rules.Rd b/R-package/man/lgb.convert_with_rules.Rd index 177b2a4dfeab..d4ef5c93eb92 100644 --- a/R-package/man/lgb.convert_with_rules.Rd +++ b/R-package/man/lgb.convert_with_rules.Rd @@ -25,6 +25,7 @@ Attempts to prepare a clean dataset to prepare to put in a \code{lgb.Dataset}. NOTE: In previous releases of LightGBM, this function was called \code{lgb.prepare_rules2}. } \examples{ +\dontrun{ data(iris) str(iris) @@ -60,5 +61,5 @@ personal_rules <- list( ) newest_iris <- lgb.convert_with_rules(data = iris, rules = personal_rules) str(newest_iris$data) # SUCCESS! - +} } diff --git a/R-package/man/lgb.cv.Rd b/R-package/man/lgb.cv.Rd index 673392f54568..d4f62c2b2207 100644 --- a/R-package/man/lgb.cv.Rd +++ b/R-package/man/lgb.cv.Rd @@ -100,6 +100,7 @@ a trained model \code{lgb.CVBooster}. Cross validation logic used by LightGBM } \examples{ +\dontrun{ data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) @@ -113,3 +114,4 @@ model <- lgb.cv( , learning_rate = 1.0 ) } +} diff --git a/R-package/man/lgb.dump.Rd b/R-package/man/lgb.dump.Rd index 6fbc5cbe9b43..bdcdcda6c237 100644 --- a/R-package/man/lgb.dump.Rd +++ b/R-package/man/lgb.dump.Rd @@ -18,7 +18,7 @@ json format of model Dump LightGBM model to json } \examples{ -\donttest{ +\dontrun{ library(lightgbm) data(agaricus.train, package = "lightgbm") train <- agaricus.train diff --git a/R-package/man/lgb.get.eval.result.Rd b/R-package/man/lgb.get.eval.result.Rd index 5707d8ccb6c4..ac88b8292315 100644 --- a/R-package/man/lgb.get.eval.result.Rd +++ b/R-package/man/lgb.get.eval.result.Rd @@ -32,6 +32,7 @@ Given a \code{lgb.Booster}, return evaluation results for a particular metric on a particular dataset. } \examples{ +\dontrun{ # train a regression model data(agaricus.train, package = "lightgbm") train <- agaricus.train @@ -59,3 +60,4 @@ print(names(model$record_evals[["test"]])) # Get L2 values for "test" dataset lgb.get.eval.result(model, "test", "l2") } +} diff --git a/R-package/man/lgb.importance.Rd b/R-package/man/lgb.importance.Rd index 5a269407859f..b1d450815a0f 100644 --- a/R-package/man/lgb.importance.Rd +++ b/R-package/man/lgb.importance.Rd @@ -24,6 +24,7 @@ For a tree model, a \code{data.table} with the following columns: Creates a \code{data.table} of feature importances in a model. } \examples{ +\dontrun{ data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) @@ -43,5 +44,5 @@ model <- lgb.train( tree_imp1 <- lgb.importance(model, percentage = TRUE) tree_imp2 <- lgb.importance(model, percentage = FALSE) - +} } diff --git a/R-package/man/lgb.interprete.Rd b/R-package/man/lgb.interprete.Rd index 86fb8ecb515b..a167de62ac6c 100644 --- a/R-package/man/lgb.interprete.Rd +++ b/R-package/man/lgb.interprete.Rd @@ -29,6 +29,7 @@ For regression, binary classification and lambdarank model, a \code{list} of \co Computes feature contribution components of rawscore prediction. } \examples{ +\dontrun{ Logit <- function(x) log(x / (1.0 - x)) data(agaricus.train, package = "lightgbm") train <- agaricus.train @@ -51,5 +52,5 @@ model <- lgb.train( ) tree_interpretation <- lgb.interprete(model, test$data, 1L:5L) - +} } diff --git a/R-package/man/lgb.load.Rd b/R-package/man/lgb.load.Rd index 72633e7baef8..399f588db4b9 100644 --- a/R-package/man/lgb.load.Rd +++ b/R-package/man/lgb.load.Rd @@ -19,7 +19,7 @@ Load LightGBM takes in either a file path or model string. If both are provided, Load will default to loading from file } \examples{ -\donttest{ +\dontrun{ data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) diff --git a/R-package/man/lgb.model.dt.tree.Rd b/R-package/man/lgb.model.dt.tree.Rd index 762ecae12777..6ef028868b9e 100644 --- a/R-package/man/lgb.model.dt.tree.Rd +++ b/R-package/man/lgb.model.dt.tree.Rd @@ -39,7 +39,7 @@ The columns of the \code{data.table} are: Parse a LightGBM model json dump into a \code{data.table} structure. } \examples{ - +\dontrun{ data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) @@ -55,5 +55,5 @@ params <- list( model <- lgb.train(params, dtrain, 10L) tree_dt <- lgb.model.dt.tree(model) - +} } diff --git a/R-package/man/lgb.plot.importance.Rd b/R-package/man/lgb.plot.importance.Rd index 024077a08409..da3914d6daaa 100644 --- a/R-package/man/lgb.plot.importance.Rd +++ b/R-package/man/lgb.plot.importance.Rd @@ -37,6 +37,7 @@ The graph represents each feature as a horizontal bar of length proportional to Features are shown ranked in a decreasing importance order. } \examples{ +\dontrun{ data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) @@ -57,3 +58,4 @@ model <- lgb.train( tree_imp <- lgb.importance(model, percentage = TRUE) lgb.plot.importance(tree_imp, top_n = 5L, measure = "Gain") } +} diff --git a/R-package/man/lgb.plot.interpretation.Rd b/R-package/man/lgb.plot.interpretation.Rd index f8266308552d..6f1cc5b8fc80 100644 --- a/R-package/man/lgb.plot.interpretation.Rd +++ b/R-package/man/lgb.plot.interpretation.Rd @@ -34,7 +34,7 @@ The graph represents each feature as a horizontal bar of length proportional to contribution of a feature. Features are shown ranked in a decreasing contribution order. } \examples{ -\donttest{ +\dontrun{ Logit <- function(x) { log(x / (1.0 - x)) } diff --git a/R-package/man/lgb.save.Rd b/R-package/man/lgb.save.Rd index 9ac19eadb3fc..119aaec8c231 100644 --- a/R-package/man/lgb.save.Rd +++ b/R-package/man/lgb.save.Rd @@ -20,7 +20,7 @@ lgb.Booster Save LightGBM model } \examples{ -\donttest{ +\dontrun{ library(lightgbm) data(agaricus.train, package = "lightgbm") train <- agaricus.train diff --git a/R-package/man/lgb.train.Rd b/R-package/man/lgb.train.Rd index b471e0c7601f..132e6aa82790 100644 --- a/R-package/man/lgb.train.Rd +++ b/R-package/man/lgb.train.Rd @@ -83,6 +83,7 @@ a trained booster model \code{lgb.Booster}. Logic to train with LightGBM } \examples{ +\dontrun{ data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) @@ -101,3 +102,4 @@ model <- lgb.train( , early_stopping_rounds = 3L ) } +} diff --git a/R-package/man/lgb.unloader.Rd b/R-package/man/lgb.unloader.Rd index 82d22b0d1eac..8aae35a98836 100644 --- a/R-package/man/lgb.unloader.Rd +++ b/R-package/man/lgb.unloader.Rd @@ -26,6 +26,7 @@ Attempts to unload LightGBM packages so you can remove objects cleanly without apparent reason and you do not want to restart R to fix the lost object. } \examples{ +\dontrun{ data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) @@ -43,7 +44,6 @@ model <- lgb.train( , learning_rate = 1.0 ) -\dontrun{ lgb.unloader(restore = FALSE, wipe = FALSE, envir = .GlobalEnv) rm(model, dtrain, dtest) # Not needed if wipe = TRUE gc() # Not needed if wipe = TRUE @@ -51,5 +51,4 @@ gc() # Not needed if wipe = TRUE library(lightgbm) # Do whatever you want again with LightGBM without object clashing } - } diff --git a/R-package/man/predict.lgb.Booster.Rd b/R-package/man/predict.lgb.Booster.Rd index 40444cbff7be..395c2d45ea37 100644 --- a/R-package/man/predict.lgb.Booster.Rd +++ b/R-package/man/predict.lgb.Booster.Rd @@ -52,6 +52,7 @@ For regression or binary classification, it returns a vector of length \code{nro Predicted values based on class \code{lgb.Booster} } \examples{ +\dontrun{ data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) @@ -70,3 +71,4 @@ model <- lgb.train( ) preds <- predict(model, test$data) } +} diff --git a/R-package/man/readRDS.lgb.Booster.Rd b/R-package/man/readRDS.lgb.Booster.Rd index 35b4ff6ea5f3..69eda2e989eb 100644 --- a/R-package/man/readRDS.lgb.Booster.Rd +++ b/R-package/man/readRDS.lgb.Booster.Rd @@ -18,7 +18,7 @@ readRDS.lgb.Booster(file = "", refhook = NULL) Attempts to load a model stored in a \code{.rds} file, using \code{\link[base]{readRDS}} } \examples{ -\donttest{ +\dontrun{ library(lightgbm) data(agaricus.train, package = "lightgbm") train <- agaricus.train diff --git a/R-package/man/saveRDS.lgb.Booster.Rd b/R-package/man/saveRDS.lgb.Booster.Rd index f267293f9d96..87b095a9c924 100644 --- a/R-package/man/saveRDS.lgb.Booster.Rd +++ b/R-package/man/saveRDS.lgb.Booster.Rd @@ -42,7 +42,7 @@ Attempts to save a model using RDS. Has an additional parameter (\code{raw}) which decides whether to save the raw model or not. } \examples{ -\donttest{ +\dontrun{ library(lightgbm) data(agaricus.train, package = "lightgbm") train <- agaricus.train diff --git a/R-package/man/setinfo.Rd b/R-package/man/setinfo.Rd index 344f79cc4621..e38811978073 100644 --- a/R-package/man/setinfo.Rd +++ b/R-package/man/setinfo.Rd @@ -38,6 +38,7 @@ The \code{name} field can be one of the following: } } \examples{ +\dontrun{ data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) @@ -48,5 +49,5 @@ lightgbm::setinfo(dtrain, "label", 1 - labels) labels2 <- lightgbm::getinfo(dtrain, "label") stopifnot(all.equal(labels2, 1 - labels)) - +} } diff --git a/R-package/man/slice.Rd b/R-package/man/slice.Rd index 90c837f222ab..587f77c80849 100644 --- a/R-package/man/slice.Rd +++ b/R-package/man/slice.Rd @@ -24,6 +24,7 @@ Get a new \code{lgb.Dataset} containing the specified rows of original \code{lgb.Dataset} object } \examples{ +\dontrun{ data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) @@ -31,5 +32,5 @@ dtrain <- lgb.Dataset(train$data, label = train$label) dsub <- lightgbm::slice(dtrain, seq_len(42L)) lgb.Dataset.construct(dsub) labels <- lightgbm::getinfo(dsub, "label") - +} } diff --git a/docs/conf.py b/docs/conf.py index 731465fef76a..3dfbf1b8503f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -247,7 +247,7 @@ def generate_r_docs(app): , install = FALSE \ , devel = FALSE \ , examples = TRUE \ - , run_dont_run = FALSE \ + , run_dont_run = TRUE \ , seed = 42L \ , preview = FALSE \ , new_process = TRUE \