From f2e1ad6f50f1795987ad92b4f4dc61c3bbb0c8f3 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 24 May 2022 10:21:43 -0500 Subject: [PATCH] [R-package] standardize style for placement of braces (#5240) --- R-package/R/lgb.convert_with_rules.R | 12 +++++++++--- R-package/R/utils.R | 8 +++++++- R-package/tests/testthat/test_learning_to_rank.R | 10 +++++++++- R-package/tests/testthat/test_lgb.Booster.R | 4 +++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/R-package/R/lgb.convert_with_rules.R b/R-package/R/lgb.convert_with_rules.R index 720be3651e2..f8b49509bc6 100644 --- a/R-package/R/lgb.convert_with_rules.R +++ b/R-package/R/lgb.convert_with_rules.R @@ -4,7 +4,9 @@ return( vapply( X = df - , FUN = function(x) {paste0(class(x), collapse = ",")} + , FUN = function(x) { + paste0(class(x), collapse = ",") + } , FUN.VALUE = character(1L) ) ) @@ -40,8 +42,12 @@ return(invisible(NULL)) } -.LGB_CONVERT_DEFAULT_FOR_LOGICAL_NA <- function() {return(-1L)} -.LGB_CONVERT_DEFAULT_FOR_NON_LOGICAL_NA <- function() {return(0L)} +.LGB_CONVERT_DEFAULT_FOR_LOGICAL_NA <- function() { + return(-1L) +} +.LGB_CONVERT_DEFAULT_FOR_NON_LOGICAL_NA <- function() { + return(0L) +} #' @name lgb.convert_with_rules diff --git a/R-package/R/utils.R b/R-package/R/utils.R index 7cbe36fe256..c8fece6fb5f 100644 --- a/R-package/R/utils.R +++ b/R-package/R/utils.R @@ -69,7 +69,13 @@ lgb.check_interaction_constraints <- function(interaction_constraints, column_na if (!methods::is(interaction_constraints, "list")) { stop("interaction_constraints must be a list") } - if (!all(sapply(interaction_constraints, function(x) {is.character(x) || is.numeric(x)}))) { + constraint_is_character_or_numeric <- sapply( + X = interaction_constraints + , FUN = function(x) { + return(is.character(x) || is.numeric(x)) + } + ) + if (!all(constraint_is_character_or_numeric)) { stop("every element in interaction_constraints must be a character vector or numeric vector") } diff --git a/R-package/tests/testthat/test_learning_to_rank.R b/R-package/tests/testthat/test_learning_to_rank.R index c7ee5f58295..8e49e2d4d56 100644 --- a/R-package/tests/testthat/test_learning_to_rank.R +++ b/R-package/tests/testthat/test_learning_to_rank.R @@ -49,7 +49,15 @@ test_that("learning-to-rank with lgb.train() works as expected", { expect_true(result[["higher_better"]]) expect_identical(result[["data_name"]], "training") } - expect_identical(sapply(eval_results, function(x) {x$name}), eval_names) + expect_identical( + sapply( + X = eval_results + , FUN = function(x) { + x$name + } + ) + , eval_names + ) expect_equal(eval_results[[1L]][["value"]], 0.775) if (!ON_32_BIT_WINDOWS) { expect_true(abs(eval_results[[2L]][["value"]] - 0.745986) < TOLERANCE) diff --git a/R-package/tests/testthat/test_lgb.Booster.R b/R-package/tests/testthat/test_lgb.Booster.R index eb1b3bbc676..fc77dfc08dc 100644 --- a/R-package/tests/testthat/test_lgb.Booster.R +++ b/R-package/tests/testthat/test_lgb.Booster.R @@ -1203,7 +1203,9 @@ test_that("boosters with linear models at leaves work with saveRDS.lgb.Booster a rm(bst) # load the booster and make predictions...should be the same - expect_warning({bst2 <- readRDS.lgb.Booster(file = model_file)}) + expect_warning({ + bst2 <- readRDS.lgb.Booster(file = model_file) + }) preds2 <- predict(bst2, X) expect_identical(preds, preds2) })