Skip to content

Commit 4359356

Browse files
authored
[R] [CI] use lintr 3.1.0 (dmlc#9456)
1 parent 1caa932 commit 4359356

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

R-package/R/xgb.model.dt.tree.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ xgb.model.dt.tree <- function(feature_names = NULL, model = NULL, text = NULL,
8686
text <- xgb.dump(model = model, with_stats = TRUE)
8787
}
8888

89-
if (length(text) < 2 ||
90-
sum(grepl('leaf=(\\d+)', text)) < 1) {
89+
if (length(text) < 2 || !any(grepl('leaf=(\\d+)', text))) {
9190
stop("Non-tree model detected! This function can only be used with tree models.")
9291
}
9392

R-package/R/xgb.plot.deepness.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ get.leaf.depth <- function(dt_tree) {
136136
# list of paths to each leaf in a tree
137137
paths <- lapply(paths_tmp$vpath, names)
138138
# combine into a resulting path lengths table for a tree
139-
data.table(Depth = sapply(paths, length), ID = To[Leaf == TRUE])
139+
data.table(Depth = lengths(paths), ID = To[Leaf == TRUE])
140140
}, by = Tree]
141141
}
142142

R-package/demo/interaction_constraints.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ treeInteractions <- function(input_tree, input_max_depth) {
4444

4545
# Remove non-interactions (same variable)
4646
interaction_list <- lapply(interaction_list, unique) # remove same variables
47-
interaction_length <- sapply(interaction_list, length)
47+
interaction_length <- lengths(interaction_list)
4848
interaction_list <- interaction_list[interaction_length > 1]
4949
interaction_list <- unique(lapply(interaction_list, sort))
5050
return(interaction_list)

R-package/tests/testthat/test_helpers.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ test_that("SHAPs sum to predictions, with or without DART", {
189189
tol <- 1e-5
190190

191191
expect_equal(rowSums(shap), pred, tol = tol)
192-
expect_equal(apply(shapi, 1, sum), pred, tol = tol)
192+
expect_equal(rowSums(shapi), pred, tol = tol)
193193
for (i in seq_len(nrow(d)))
194194
for (f in list(rowSums, colSums))
195195
expect_equal(f(shapi[i, , ]), shap[i, ], tol = tol)

tests/ci_build/lint_r.R

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,23 @@ my_linters <- list(
2020
any_duplicated = lintr::any_duplicated_linter(),
2121
any_is_na = lintr::any_is_na_linter(),
2222
assignment_linter = lintr::assignment_linter(),
23+
boolean_arithmetic = lintr::boolean_arithmetic_linter(),
2324
brace_linter = lintr::brace_linter(),
25+
class_equals = lintr::class_equals_linter(),
2426
commas_linter = lintr::commas_linter(),
27+
empty_assignment = lintr::empty_assignment_linter(),
2528
equals_na = lintr::equals_na_linter(),
2629
fixed_regex = lintr::fixed_regex_linter(),
30+
for_loop_index = lintr::for_loop_index_linter(),
31+
function_return = lintr::function_return_linter(),
2732
infix_spaces_linter = lintr::infix_spaces_linter(),
33+
is_numeric = lintr::is_numeric_linter(),
2834
line_length_linter = lintr::line_length_linter(length = 150L),
29-
no_tab_linter = lintr::no_tab_linter(),
35+
lengths = lintr::lengths_linter(),
36+
matrix = lintr::matrix_apply_linter(),
3037
object_usage_linter = lintr::object_usage_linter(),
3138
object_length_linter = lintr::object_length_linter(),
39+
routine_registration = lintr::routine_registration_linter(),
3240
semicolon = lintr::semicolon_linter(),
3341
seq = lintr::seq_linter(),
3442
spaces_inside_linter = lintr::spaces_inside_linter(),
@@ -37,9 +45,10 @@ my_linters <- list(
3745
trailing_blank_lines_linter = lintr::trailing_blank_lines_linter(),
3846
trailing_whitespace_linter = lintr::trailing_whitespace_linter(),
3947
true_false = lintr::T_and_F_symbol_linter(),
40-
unneeded_concatenation = lintr::unneeded_concatenation_linter(),
48+
unnecessary_concatenation = lintr::unnecessary_concatenation_linter(),
4149
unreachable_code = lintr::unreachable_code_linter(),
42-
vector_logic = lintr::vector_logic_linter()
50+
vector_logic = lintr::vector_logic_linter(),
51+
whitespace = lintr::whitespace_linter()
4352
)
4453

4554
noquote(paste0(length(FILES_TO_LINT), " R files need linting"))

0 commit comments

Comments
 (0)