From d6fb3d96419a53ae2062c38d1737a6d3743f2993 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Thu, 16 Apr 2020 04:46:40 +0100 Subject: [PATCH 1/4] [R-package] fix R examples and lgb.plot.interpretation --- .gitignore | 9 +++++++++ R-package/DESCRIPTION | 2 +- R-package/R/lgb.Booster.R | 2 +- R-package/R/lgb.Dataset.R | 4 ++-- R-package/R/lgb.plot.interpretation.R | 4 ++-- R-package/R/lgb.prepare_rules.R | 10 +++++++--- R-package/R/saveRDS.lgb.Booster.R | 2 +- R-package/man/agaricus.test.Rd | 6 ++++-- R-package/man/agaricus.train.Rd | 6 ++++-- R-package/man/bank.Rd | 4 +++- R-package/man/lgb.Dataset.set.categorical.Rd | 4 ++-- R-package/man/lgb.plot.interpretation.Rd | 2 +- R-package/man/lgb.prepare_rules.Rd | 10 +++++++--- R-package/man/lgb.save.Rd | 2 +- R-package/man/saveRDS.lgb.Booster.Rd | 2 +- docs/conf.py | 2 +- 16 files changed, 47 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 283349aee0fa..ec3115fbf04b 100644 --- a/.gitignore +++ b/.gitignore @@ -406,6 +406,15 @@ lightgbm_r/* lightgbm*.tar.gz lightgbm.Rcheck/ +# Files created by R examples and tests +**/lgb-Dataset.data +**/lgb-model.rds +**/lgb.Dataset.data +**/model.rds +**/model.txt +**/lgb-model.txt + + # Files from interactive R sessions .Rproj.user **/.Rhistory diff --git a/R-package/DESCRIPTION b/R-package/DESCRIPTION index 55df4a779eb3..1924b6a1d666 100755 --- a/R-package/DESCRIPTION +++ b/R-package/DESCRIPTION @@ -41,4 +41,4 @@ Imports: utils SystemRequirements: C++11 -RoxygenNote: 7.0.2 +RoxygenNote: 7.1.0 diff --git a/R-package/R/lgb.Booster.R b/R-package/R/lgb.Booster.R index 3e1bd0de0b78..d912cd871a57 100644 --- a/R-package/R/lgb.Booster.R +++ b/R-package/R/lgb.Booster.R @@ -845,7 +845,7 @@ lgb.load <- function(filename = NULL, model_str = NULL) { #' , learning_rate = 1.0 #' , early_stopping_rounds = 5L #' ) -#' lgb.save(model, "model.txt") +#' lgb.save(model, "lgb-model.txt") #' } #' @export lgb.save <- function(booster, filename, num_iteration = NULL) { diff --git a/R-package/R/lgb.Dataset.R b/R-package/R/lgb.Dataset.R index 22afc2666718..fed95913d2d6 100644 --- a/R-package/R/lgb.Dataset.R +++ b/R-package/R/lgb.Dataset.R @@ -1073,8 +1073,8 @@ setinfo.lgb.Dataset <- function(dataset, name, info, ...) { #' data(agaricus.train, package = "lightgbm") #' train <- agaricus.train #' dtrain <- lgb.Dataset(train$data, label = train$label) -#' lgb.Dataset.save(dtrain, "lgb.Dataset.data") -#' dtrain <- lgb.Dataset("lgb.Dataset.data") +#' lgb.Dataset.save(dtrain, "lgb-Dataset.data") +#' dtrain <- lgb.Dataset("lgb-Dataset.data") #' lgb.Dataset.set.categorical(dtrain, 1L:2L) #' #' @rdname lgb.Dataset.set.categorical diff --git a/R-package/R/lgb.plot.interpretation.R b/R-package/R/lgb.plot.interpretation.R index 0efd71ccc929..486b80dd46dd 100644 --- a/R-package/R/lgb.plot.interpretation.R +++ b/R-package/R/lgb.plot.interpretation.R @@ -49,7 +49,7 @@ #' ) #' lgb.plot.interpretation( #' tree_interpretation_dt = tree_interpretation[[1L]] -#' , top_n = 5L +#' , top_n = 3L #' ) #' } #' @importFrom data.table setnames @@ -141,7 +141,7 @@ multiple.tree.plot.interpretation <- function(tree_interpretation, } # create plot - tree_interpretation[Contribution > 0.0, bar_color := "firebrick"] + tree_interpretation[abs(Contribution) > 0.0, bar_color := "firebrick"] tree_interpretation[Contribution == 0.0, bar_color := "steelblue"] tree_interpretation[.N:1L, graphics::barplot( diff --git a/R-package/R/lgb.prepare_rules.R b/R-package/R/lgb.prepare_rules.R index 307a69e32a38..3eda16672ce7 100644 --- a/R-package/R/lgb.prepare_rules.R +++ b/R-package/R/lgb.prepare_rules.R @@ -36,9 +36,13 @@ #' data(iris) # Erase iris dataset #' #' # We remapped values differently -#' personal_rules <- list(Species = c("setosa" = 3L, -#' "versicolor" = 2L, -#' "virginica" = 1L)) +#' personal_rules <- list( +#' Species = c( +#' "setosa" = 3L +#' , "versicolor" = 2L +#' , "virginica" = 1L +#' ) +#' ) #' newest_iris <- lgb.prepare_rules(data = iris, rules = personal_rules) #' str(newest_iris$data) # SUCCESS! #' diff --git a/R-package/R/saveRDS.lgb.Booster.R b/R-package/R/saveRDS.lgb.Booster.R index 855e1e1b6c8e..185186c9bc25 100644 --- a/R-package/R/saveRDS.lgb.Booster.R +++ b/R-package/R/saveRDS.lgb.Booster.R @@ -37,7 +37,7 @@ #' , learning_rate = 1.0 #' , early_stopping_rounds = 5L #' ) -#' saveRDS.lgb.Booster(model, "model.rds") +#' saveRDS.lgb.Booster(model, "lgb-model.rds") #' } #' @export saveRDS.lgb.Booster <- function(object, diff --git a/R-package/man/agaricus.test.Rd b/R-package/man/agaricus.test.Rd index c713cbde6a9a..aad4627eedae 100644 --- a/R-package/man/agaricus.test.Rd +++ b/R-package/man/agaricus.test.Rd @@ -4,8 +4,10 @@ \name{agaricus.test} \alias{agaricus.test} \title{Test part from Mushroom Data Set} -\format{A list containing a label vector, and a dgCMatrix object with 1611 -rows and 126 variables} +\format{ +A list containing a label vector, and a dgCMatrix object with 1611 +rows and 126 variables +} \usage{ data(agaricus.test) } diff --git a/R-package/man/agaricus.train.Rd b/R-package/man/agaricus.train.Rd index 9465a6efea29..62b7d05a0bc3 100644 --- a/R-package/man/agaricus.train.Rd +++ b/R-package/man/agaricus.train.Rd @@ -4,8 +4,10 @@ \name{agaricus.train} \alias{agaricus.train} \title{Training part from Mushroom Data Set} -\format{A list containing a label vector, and a dgCMatrix object with 6513 -rows and 127 variables} +\format{ +A list containing a label vector, and a dgCMatrix object with 6513 +rows and 127 variables +} \usage{ data(agaricus.train) } diff --git a/R-package/man/bank.Rd b/R-package/man/bank.Rd index fd1382eb87d8..3b4c13b24d54 100644 --- a/R-package/man/bank.Rd +++ b/R-package/man/bank.Rd @@ -4,7 +4,9 @@ \name{bank} \alias{bank} \title{Bank Marketing Data Set} -\format{A data.table with 4521 rows and 17 variables} +\format{ +A data.table with 4521 rows and 17 variables +} \usage{ data(bank) } diff --git a/R-package/man/lgb.Dataset.set.categorical.Rd b/R-package/man/lgb.Dataset.set.categorical.Rd index 0ab44b56bb0d..097eea02b465 100644 --- a/R-package/man/lgb.Dataset.set.categorical.Rd +++ b/R-package/man/lgb.Dataset.set.categorical.Rd @@ -24,8 +24,8 @@ Set the categorical features of an \code{lgb.Dataset} object. Use this function data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) -lgb.Dataset.save(dtrain, "lgb.Dataset.data") -dtrain <- lgb.Dataset("lgb.Dataset.data") +lgb.Dataset.save(dtrain, "lgb-Dataset.data") +dtrain <- lgb.Dataset("lgb-Dataset.data") lgb.Dataset.set.categorical(dtrain, 1L:2L) } diff --git a/R-package/man/lgb.plot.interpretation.Rd b/R-package/man/lgb.plot.interpretation.Rd index b8818eecdbc0..f8266308552d 100644 --- a/R-package/man/lgb.plot.interpretation.Rd +++ b/R-package/man/lgb.plot.interpretation.Rd @@ -68,7 +68,7 @@ tree_interpretation <- lgb.interprete( ) lgb.plot.interpretation( tree_interpretation_dt = tree_interpretation[[1L]] - , top_n = 5L + , top_n = 3L ) } } diff --git a/R-package/man/lgb.prepare_rules.Rd b/R-package/man/lgb.prepare_rules.Rd index 69821ef7d240..cc34bf11ca5c 100644 --- a/R-package/man/lgb.prepare_rules.Rd +++ b/R-package/man/lgb.prepare_rules.Rd @@ -48,9 +48,13 @@ all.equal(new_iris$data, newer_iris$data) data(iris) # Erase iris dataset # We remapped values differently -personal_rules <- list(Species = c("setosa" = 3L, - "versicolor" = 2L, - "virginica" = 1L)) +personal_rules <- list( + Species = c( + "setosa" = 3L + , "versicolor" = 2L + , "virginica" = 1L + ) +) newest_iris <- lgb.prepare_rules(data = iris, rules = personal_rules) str(newest_iris$data) # SUCCESS! diff --git a/R-package/man/lgb.save.Rd b/R-package/man/lgb.save.Rd index 91e2befb738f..f1ffd48355ee 100644 --- a/R-package/man/lgb.save.Rd +++ b/R-package/man/lgb.save.Rd @@ -39,6 +39,6 @@ model <- lgb.train( , learning_rate = 1.0 , early_stopping_rounds = 5L ) -lgb.save(model, "model.txt") +lgb.save(model, "lgb-model.txt") } } diff --git a/R-package/man/saveRDS.lgb.Booster.Rd b/R-package/man/saveRDS.lgb.Booster.Rd index 3e7bb368d878..66afa861db9f 100644 --- a/R-package/man/saveRDS.lgb.Booster.Rd +++ b/R-package/man/saveRDS.lgb.Booster.Rd @@ -61,6 +61,6 @@ model <- lgb.train( , learning_rate = 1.0 , early_stopping_rounds = 5L ) -saveRDS.lgb.Booster(model, "model.rds") +saveRDS.lgb.Booster(model, "lgb-model.rds") } } diff --git a/docs/conf.py b/docs/conf.py index c157566d3805..6ffb0c1eba83 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -227,7 +227,7 @@ def generate_r_docs(app): /home/docs/.conda/bin/conda create -q -y -n r_env \ r-base=3.5.1=h1e0a451_2 \ r-devtools=1.13.6=r351h6115d3f_0 \ - r-data.table=1.11.4=r351h96ca727_0 \ + r-data.table=1.12.2=r36h96ca727_0 \ r-jsonlite=1.5=r351h96ca727_0 \ r-matrix=1.2_14=r351h96ca727_0 \ r-testthat=2.0.0=r351h29659fb_0 \ From 1ad813cb0ff4b6b25805fa68136364ba44d291ba Mon Sep 17 00:00:00 2001 From: James Lamb Date: Thu, 16 Apr 2020 05:06:21 +0100 Subject: [PATCH 2/4] remove space in gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index ec3115fbf04b..5a06037ed68f 100644 --- a/.gitignore +++ b/.gitignore @@ -414,7 +414,6 @@ lightgbm.Rcheck/ **/model.txt **/lgb-model.txt - # Files from interactive R sessions .Rproj.user **/.Rhistory From e0cc4e6f042f1cce358eaf94a6a84e3ff33d8bdd Mon Sep 17 00:00:00 2001 From: Nikita Titov Date: Fri, 17 Apr 2020 16:51:55 +0300 Subject: [PATCH 3/4] try data.table from conda-forge --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 6ffb0c1eba83..cf499354ee54 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -227,13 +227,13 @@ def generate_r_docs(app): /home/docs/.conda/bin/conda create -q -y -n r_env \ r-base=3.5.1=h1e0a451_2 \ r-devtools=1.13.6=r351h6115d3f_0 \ - r-data.table=1.12.2=r36h96ca727_0 \ r-jsonlite=1.5=r351h96ca727_0 \ r-matrix=1.2_14=r351h96ca727_0 \ r-testthat=2.0.0=r351h29659fb_0 \ cmake=3.14.0=h52cb24c_0 \ ca-certificates=2019.11.27=0 /home/docs/.conda/bin/conda install -q -y -n r_env -c conda-forge \ + r-data.table=1.12.8=r35hcdcec82_0 \ r-pkgdown=1.3.0=r35h6115d3f_1001 \ r-roxygen2=6.1.1=r35h0357c0b_1001 source /home/docs/.conda/bin/activate r_env From 0eb02430c3425407f5a43b7aa38f98bc07211f5f Mon Sep 17 00:00:00 2001 From: James Lamb Date: Sat, 18 Apr 2020 10:00:46 -0500 Subject: [PATCH 4/4] update FAQ --- docs/FAQ.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/FAQ.rst b/docs/FAQ.rst index 8816a4430f97..6b8e107f9fde 100644 --- a/docs/FAQ.rst +++ b/docs/FAQ.rst @@ -210,7 +210,7 @@ This is a known bug: `Microsoft/LightGBM#539 `_. If you use ``lgb.dl()`` to build from source (i.e. not using pre-compiled dll), you need to upgrade your version of ``data.table`` to at least version 1.12.0. +If you are experiencing this error when running ``lightgbm``, you may be facing the same issue reported in `#2715 `_ and later in `#2989 `_. We have seen that some in some situations, using ``data.table`` 1.11.x results in this error. To get around this, you can upgrade your version of ``data.table`` to at least version 1.12.0. ------