"src/git@developer.sourcefind.cn:tianlh/lightgbm-dcu.git" did not exist on "ba5c74597c5e0a07c9e1d0ecd8f6416e08348f0b"
Unverified Commit c454d5f8 authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

[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: default avatarNikita Titov <nekit94-08@mail.ru>
parent 6f54ec3d
...@@ -13,9 +13,10 @@ lgb.Dataset.construct(dataset) ...@@ -13,9 +13,10 @@ lgb.Dataset.construct(dataset)
Construct Dataset explicitly Construct Dataset explicitly
} }
\examples{ \examples{
\dontrun{
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label) dtrain <- lgb.Dataset(train$data, label = train$label)
lgb.Dataset.construct(dtrain) lgb.Dataset.construct(dtrain)
}
} }
...@@ -22,11 +22,12 @@ constructed dataset ...@@ -22,11 +22,12 @@ constructed dataset
Construct validation data according to training data Construct validation data according to training data
} }
\examples{ \examples{
\dontrun{
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label) dtrain <- lgb.Dataset(train$data, label = train$label)
data(agaricus.test, package = "lightgbm") data(agaricus.test, package = "lightgbm")
test <- agaricus.test test <- agaricus.test
dtest <- lgb.Dataset.create.valid(dtrain, test$data, label = test$label) dtest <- lgb.Dataset.create.valid(dtrain, test$data, label = test$label)
}
} }
...@@ -19,8 +19,10 @@ Please note that \code{init_score} is not saved in binary file. ...@@ -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. If you need it, please set it again after loading Dataset.
} }
\examples{ \examples{
\dontrun{
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label) dtrain <- lgb.Dataset(train$data, label = train$label)
lgb.Dataset.save(dtrain, tempfile(fileext = ".bin")) lgb.Dataset.save(dtrain, tempfile(fileext = ".bin"))
} }
}
...@@ -21,6 +21,7 @@ Set the categorical features of an \code{lgb.Dataset} object. Use this function ...@@ -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. to tell LightGBM which features should be treated as categorical.
} }
\examples{ \examples{
\dontrun{
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label) dtrain <- lgb.Dataset(train$data, label = train$label)
...@@ -28,5 +29,5 @@ data_file <- tempfile(fileext = ".data") ...@@ -28,5 +29,5 @@ data_file <- tempfile(fileext = ".data")
lgb.Dataset.save(dtrain, data_file) lgb.Dataset.save(dtrain, data_file)
dtrain <- lgb.Dataset(data_file) dtrain <- lgb.Dataset(data_file)
lgb.Dataset.set.categorical(dtrain, 1L:2L) lgb.Dataset.set.categorical(dtrain, 1L:2L)
}
} }
...@@ -18,6 +18,7 @@ passed dataset ...@@ -18,6 +18,7 @@ passed dataset
If you want to use validation data, you should set reference to training data If you want to use validation data, you should set reference to training data
} }
\examples{ \examples{
\dontrun{
data(agaricus.train, package ="lightgbm") data(agaricus.train, package ="lightgbm")
train <- agaricus.train train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label) dtrain <- lgb.Dataset(train$data, label = train$label)
...@@ -25,5 +26,5 @@ data(agaricus.test, package = "lightgbm") ...@@ -25,5 +26,5 @@ data(agaricus.test, package = "lightgbm")
test <- agaricus.test test <- agaricus.test
dtest <- lgb.Dataset(test$data, test = train$label) dtest <- lgb.Dataset(test$data, test = train$label)
lgb.Dataset.set.reference(dtest, dtrain) lgb.Dataset.set.reference(dtest, dtrain)
}
} }
...@@ -23,6 +23,7 @@ Attempts to prepare a clean dataset to prepare to put in a \code{lgb.Dataset}. ...@@ -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}. NOTE: In previous releases of LightGBM, this function was called \code{lgb.prepare}.
} }
\examples{ \examples{
\dontrun{
data(iris) data(iris)
str(iris) str(iris)
...@@ -30,11 +31,10 @@ str(iris) ...@@ -30,11 +31,10 @@ str(iris)
# Convert all factors/chars to integer # Convert all factors/chars to integer
str(lgb.convert(data = iris)) str(lgb.convert(data = iris))
\dontrun{
# When lightgbm package is installed, and you do not want to load it # When lightgbm package is installed, and you do not want to load it
# You can still use the function! # You can still use the function!
lgb.unloader() lgb.unloader()
str(lightgbm::lgb.convert(data = iris)) str(lgb.convert(data = iris))
# 'data.frame': 150 obs. of 5 variables: # '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.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 ... # $ 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)) ...@@ -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 ... # $ 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 ... # $ Species : int 1 1 1 1 1 1 1 1 1 1 ...
} }
} }
...@@ -25,6 +25,7 @@ Attempts to prepare a clean dataset to prepare to put in a \code{lgb.Dataset}. ...@@ -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}. NOTE: In previous releases of LightGBM, this function was called \code{lgb.prepare_rules2}.
} }
\examples{ \examples{
\dontrun{
data(iris) data(iris)
str(iris) str(iris)
...@@ -60,5 +61,5 @@ personal_rules <- list( ...@@ -60,5 +61,5 @@ personal_rules <- list(
) )
newest_iris <- lgb.convert_with_rules(data = iris, rules = personal_rules) newest_iris <- lgb.convert_with_rules(data = iris, rules = personal_rules)
str(newest_iris$data) # SUCCESS! str(newest_iris$data) # SUCCESS!
}
} }
...@@ -100,6 +100,7 @@ a trained model \code{lgb.CVBooster}. ...@@ -100,6 +100,7 @@ a trained model \code{lgb.CVBooster}.
Cross validation logic used by LightGBM Cross validation logic used by LightGBM
} }
\examples{ \examples{
\dontrun{
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label) dtrain <- lgb.Dataset(train$data, label = train$label)
...@@ -113,3 +114,4 @@ model <- lgb.cv( ...@@ -113,3 +114,4 @@ model <- lgb.cv(
, learning_rate = 1.0 , learning_rate = 1.0
) )
} }
}
...@@ -18,7 +18,7 @@ json format of model ...@@ -18,7 +18,7 @@ json format of model
Dump LightGBM model to json Dump LightGBM model to json
} }
\examples{ \examples{
\donttest{ \dontrun{
library(lightgbm) library(lightgbm)
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
......
...@@ -32,6 +32,7 @@ Given a \code{lgb.Booster}, return evaluation results for a ...@@ -32,6 +32,7 @@ Given a \code{lgb.Booster}, return evaluation results for a
particular metric on a particular dataset. particular metric on a particular dataset.
} }
\examples{ \examples{
\dontrun{
# train a regression model # train a regression model
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
...@@ -59,3 +60,4 @@ print(names(model$record_evals[["test"]])) ...@@ -59,3 +60,4 @@ print(names(model$record_evals[["test"]]))
# Get L2 values for "test" dataset # Get L2 values for "test" dataset
lgb.get.eval.result(model, "test", "l2") lgb.get.eval.result(model, "test", "l2")
} }
}
...@@ -24,6 +24,7 @@ For a tree model, a \code{data.table} with the following columns: ...@@ -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. Creates a \code{data.table} of feature importances in a model.
} }
\examples{ \examples{
\dontrun{
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label) dtrain <- lgb.Dataset(train$data, label = train$label)
...@@ -43,5 +44,5 @@ model <- lgb.train( ...@@ -43,5 +44,5 @@ model <- lgb.train(
tree_imp1 <- lgb.importance(model, percentage = TRUE) tree_imp1 <- lgb.importance(model, percentage = TRUE)
tree_imp2 <- lgb.importance(model, percentage = FALSE) tree_imp2 <- lgb.importance(model, percentage = FALSE)
}
} }
...@@ -29,6 +29,7 @@ For regression, binary classification and lambdarank model, a \code{list} of \co ...@@ -29,6 +29,7 @@ For regression, binary classification and lambdarank model, a \code{list} of \co
Computes feature contribution components of rawscore prediction. Computes feature contribution components of rawscore prediction.
} }
\examples{ \examples{
\dontrun{
Logit <- function(x) log(x / (1.0 - x)) Logit <- function(x) log(x / (1.0 - x))
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
...@@ -51,5 +52,5 @@ model <- lgb.train( ...@@ -51,5 +52,5 @@ model <- lgb.train(
) )
tree_interpretation <- lgb.interprete(model, test$data, 1L:5L) tree_interpretation <- lgb.interprete(model, test$data, 1L:5L)
}
} }
...@@ -19,7 +19,7 @@ Load LightGBM takes in either a file path or model string. ...@@ -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 If both are provided, Load will default to loading from file
} }
\examples{ \examples{
\donttest{ \dontrun{
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label) dtrain <- lgb.Dataset(train$data, label = train$label)
......
...@@ -39,7 +39,7 @@ The columns of the \code{data.table} are: ...@@ -39,7 +39,7 @@ The columns of the \code{data.table} are:
Parse a LightGBM model json dump into a \code{data.table} structure. Parse a LightGBM model json dump into a \code{data.table} structure.
} }
\examples{ \examples{
\dontrun{
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label) dtrain <- lgb.Dataset(train$data, label = train$label)
...@@ -55,5 +55,5 @@ params <- list( ...@@ -55,5 +55,5 @@ params <- list(
model <- lgb.train(params, dtrain, 10L) model <- lgb.train(params, dtrain, 10L)
tree_dt <- lgb.model.dt.tree(model) tree_dt <- lgb.model.dt.tree(model)
}
} }
...@@ -37,6 +37,7 @@ The graph represents each feature as a horizontal bar of length proportional to ...@@ -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. Features are shown ranked in a decreasing importance order.
} }
\examples{ \examples{
\dontrun{
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label) dtrain <- lgb.Dataset(train$data, label = train$label)
...@@ -57,3 +58,4 @@ model <- lgb.train( ...@@ -57,3 +58,4 @@ model <- lgb.train(
tree_imp <- lgb.importance(model, percentage = TRUE) tree_imp <- lgb.importance(model, percentage = TRUE)
lgb.plot.importance(tree_imp, top_n = 5L, measure = "Gain") lgb.plot.importance(tree_imp, top_n = 5L, measure = "Gain")
} }
}
...@@ -34,7 +34,7 @@ The graph represents each feature as a horizontal bar of length proportional to ...@@ -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. contribution of a feature. Features are shown ranked in a decreasing contribution order.
} }
\examples{ \examples{
\donttest{ \dontrun{
Logit <- function(x) { Logit <- function(x) {
log(x / (1.0 - x)) log(x / (1.0 - x))
} }
......
...@@ -20,7 +20,7 @@ lgb.Booster ...@@ -20,7 +20,7 @@ lgb.Booster
Save LightGBM model Save LightGBM model
} }
\examples{ \examples{
\donttest{ \dontrun{
library(lightgbm) library(lightgbm)
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
......
...@@ -83,6 +83,7 @@ a trained booster model \code{lgb.Booster}. ...@@ -83,6 +83,7 @@ a trained booster model \code{lgb.Booster}.
Logic to train with LightGBM Logic to train with LightGBM
} }
\examples{ \examples{
\dontrun{
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label) dtrain <- lgb.Dataset(train$data, label = train$label)
...@@ -101,3 +102,4 @@ model <- lgb.train( ...@@ -101,3 +102,4 @@ model <- lgb.train(
, early_stopping_rounds = 3L , early_stopping_rounds = 3L
) )
} }
}
...@@ -26,6 +26,7 @@ Attempts to unload LightGBM packages so you can remove objects cleanly without ...@@ -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. apparent reason and you do not want to restart R to fix the lost object.
} }
\examples{ \examples{
\dontrun{
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label) dtrain <- lgb.Dataset(train$data, label = train$label)
...@@ -43,7 +44,6 @@ model <- lgb.train( ...@@ -43,7 +44,6 @@ model <- lgb.train(
, learning_rate = 1.0 , learning_rate = 1.0
) )
\dontrun{
lgb.unloader(restore = FALSE, wipe = FALSE, envir = .GlobalEnv) lgb.unloader(restore = FALSE, wipe = FALSE, envir = .GlobalEnv)
rm(model, dtrain, dtest) # Not needed if wipe = TRUE rm(model, dtrain, dtest) # Not needed if wipe = TRUE
gc() # Not needed if wipe = TRUE gc() # Not needed if wipe = TRUE
...@@ -51,5 +51,4 @@ gc() # Not needed if wipe = TRUE ...@@ -51,5 +51,4 @@ gc() # Not needed if wipe = TRUE
library(lightgbm) library(lightgbm)
# Do whatever you want again with LightGBM without object clashing # Do whatever you want again with LightGBM without object clashing
} }
} }
...@@ -52,6 +52,7 @@ For regression or binary classification, it returns a vector of length \code{nro ...@@ -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} Predicted values based on class \code{lgb.Booster}
} }
\examples{ \examples{
\dontrun{
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label) dtrain <- lgb.Dataset(train$data, label = train$label)
...@@ -70,3 +71,4 @@ model <- lgb.train( ...@@ -70,3 +71,4 @@ model <- lgb.train(
) )
preds <- predict(model, test$data) preds <- predict(model, test$data)
} }
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment