Skip to content

Commit

Permalink
[R-package] standardize style for placement of braces (#5240)
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb authored May 24, 2022
1 parent a4478f7 commit f2e1ad6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
12 changes: 9 additions & 3 deletions R-package/R/lgb.convert_with_rules.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion R-package/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
10 changes: 9 additions & 1 deletion R-package/tests/testthat/test_learning_to_rank.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion R-package/tests/testthat/test_lgb.Booster.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down

0 comments on commit f2e1ad6

Please sign in to comment.