From d807aa3ef95b200b2c85db449d802dd77240988a Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 23 Oct 2019 21:22:31 -0500 Subject: [PATCH] more minor changes to style --- R-package/R/callback.R | 2 +- R-package/R/lgb.Booster.R | 4 ++-- R-package/R/lgb.cv.R | 2 +- R-package/R/lgb.importance.R | 8 +++++--- R-package/demo/leaf_stability.R | 6 +++--- R-package/src/install.libs.R | 2 +- R-package/tests/testthat/test_basic.R | 2 +- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/R-package/R/callback.R b/R-package/R/callback.R index 77bb7111ca56..92bd9c035a97 100644 --- a/R-package/R/callback.R +++ b/R-package/R/callback.R @@ -170,7 +170,7 @@ cb.print.evaluation <- function(period = 1) { i <- env$iteration # Check if iteration matches moduo - if ((i - 1) %% period == 0 || is.element(i, c(env$begin_iteration, env$end_iteration ))) { + if ( (i - 1) %% period == 0 || is.element(i, c(env$begin_iteration, env$end_iteration))) { # Merge evaluation string msg <- merge.eval.string(env) diff --git a/R-package/R/lgb.Booster.R b/R-package/R/lgb.Booster.R index 332ddc2a5fea..a23245533b06 100644 --- a/R-package/R/lgb.Booster.R +++ b/R-package/R/lgb.Booster.R @@ -255,7 +255,7 @@ Booster <- R6::R6Class( gpair <- fobj(private$inner_predict(1), private$train_set) # Check for gradient and hessian as list - if(is.null(gpair$grad) || is.null(gpair$hess)){ + if (is.null(gpair$grad) || is.null(gpair$hess)){ stop("lgb.Booster.update: custom objective should return a list with attributes (hess, grad)") } @@ -635,7 +635,7 @@ Booster <- R6::R6Class( res <- feval(private$inner_predict(data_idx), data) # Check for name correctness - if(is.null(res$name) || is.null(res$value) || is.null(res$higher_better)) { + if (is.null(res$name) || is.null(res$value) || is.null(res$higher_better)) { stop("lgb.Booster.eval: custom eval function should return a list with attribute (name, value, higher_better)"); } diff --git a/R-package/R/lgb.cv.R b/R-package/R/lgb.cv.R index 342b13a0dc3c..594b323df16d 100644 --- a/R-package/R/lgb.cv.R +++ b/R-package/R/lgb.cv.R @@ -318,7 +318,7 @@ lgb.cv <- function(params = list(), env$eval_list <- merged_msg$eval_list # Check for standard deviation requirement - if(showsd) { + if (showsd) { env$eval_err_list <- merged_msg$eval_err_list } diff --git a/R-package/R/lgb.importance.R b/R-package/R/lgb.importance.R index 47247e7d6f51..ba9d02476166 100644 --- a/R-package/R/lgb.importance.R +++ b/R-package/R/lgb.importance.R @@ -68,9 +68,11 @@ lgb.importance <- function(model, percentage = TRUE) { # Check if relative values are requested if (percentage) { - tree_imp_dt[, ":="(Gain = Gain / sum(Gain), - Cover = Cover / sum(Cover), - Frequency = Frequency / sum(Frequency))] + tree_imp_dt[, `:=`( + Gain = Gain / sum(Gain) + , Cover = Cover / sum(Cover) + , Frequency = Frequency / sum(Frequency) + )] } # Return importance table diff --git a/R-package/demo/leaf_stability.R b/R-package/demo/leaf_stability.R index af201f9e1559..b97fc3e5e241 100644 --- a/R-package/demo/leaf_stability.R +++ b/R-package/demo/leaf_stability.R @@ -48,7 +48,7 @@ new_data <- data.frame( , 1 - 1e-15 ) ) -new_data$Z <- -(agaricus.test$label * log(new_data$Y) + (1 - agaricus.test$label) * log(1 - new_data$Y)) +new_data$Z <- -1 * (agaricus.test$label * log(new_data$Y) + (1 - agaricus.test$label) * log(1 - new_data$Y)) new_data$binned <- .bincode( x = new_data$X , breaks = quantile( @@ -115,7 +115,7 @@ new_data2 <- data.frame( , 1 - 1e-15 ) ) -new_data2$Z <- -(agaricus.test$label * log(new_data2$Y) + (1 - agaricus.test$label) * log(1 - new_data2$Y)) +new_data2$Z <- -1 * (agaricus.test$label * log(new_data2$Y) + (1 - agaricus.test$label) * log(1 - new_data2$Y)) new_data2$binned <- .bincode( x = new_data2$X , breaks = quantile( @@ -183,7 +183,7 @@ new_data3 <- data.frame( , 1 - 1e-15 ) ) -new_data3$Z <- -(agaricus.test$label * log(new_data3$Y) + (1 - agaricus.test$label) * log(1 - new_data3$Y)) +new_data3$Z <- -1 * (agaricus.test$label * log(new_data3$Y) + (1 - agaricus.test$label) * log(1 - new_data3$Y)) new_data3$binned <- .bincode( x = new_data3$X , breaks = quantile( diff --git a/R-package/src/install.libs.R b/R-package/src/install.libs.R index 72451a0e1daf..2ab2a6a77af0 100644 --- a/R-package/src/install.libs.R +++ b/R-package/src/install.libs.R @@ -74,7 +74,7 @@ if (!use_precompile) { try_vs <- 0 local_vs_def <- "" vs_versions <- c("Visual Studio 16 2019", "Visual Studio 15 2017", "Visual Studio 14 2015") - for(vs in vs_versions){ + for (vs in vs_versions){ vs_def <- paste0(" -G \"", vs, "\" -A x64") tmp_cmake_cmd <- paste0(cmake_cmd, vs_def) try_vs <- system(paste0(tmp_cmake_cmd, " ..")) diff --git a/R-package/tests/testthat/test_basic.R b/R-package/tests/testthat/test_basic.R index 678b1775f9a1..90925196a5f1 100644 --- a/R-package/tests/testthat/test_basic.R +++ b/R-package/tests/testthat/test_basic.R @@ -26,7 +26,7 @@ test_that("train and predict binary classification", { pred1 <- predict(bst, train$data, num_iteration = 1) expect_equal(length(pred1), 6513) - err_pred1 <- sum((pred1 > 0.5) != train$label) / length(train$label) + err_pred1 <- sum( (pred1 > 0.5) != train$label) / length(train$label) err_log <- record_results[1] expect_lt(abs(err_pred1 - err_log), 10e-6) })