[R] [CI] use lintr 3.1.0 (#9456)

This commit is contained in:
James Lamb 2023-08-10 04:49:16 -05:00 committed by GitHub
parent 1caa93221a
commit 4359356d46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 8 deletions

View File

@ -86,8 +86,7 @@ xgb.model.dt.tree <- function(feature_names = NULL, model = NULL, text = NULL,
text <- xgb.dump(model = model, with_stats = TRUE)
}
if (length(text) < 2 ||
sum(grepl('leaf=(\\d+)', text)) < 1) {
if (length(text) < 2 || !any(grepl('leaf=(\\d+)', text))) {
stop("Non-tree model detected! This function can only be used with tree models.")
}

View File

@ -136,7 +136,7 @@ get.leaf.depth <- function(dt_tree) {
# list of paths to each leaf in a tree
paths <- lapply(paths_tmp$vpath, names)
# combine into a resulting path lengths table for a tree
data.table(Depth = sapply(paths, length), ID = To[Leaf == TRUE])
data.table(Depth = lengths(paths), ID = To[Leaf == TRUE])
}, by = Tree]
}

View File

@ -44,7 +44,7 @@ treeInteractions <- function(input_tree, input_max_depth) {
# Remove non-interactions (same variable)
interaction_list <- lapply(interaction_list, unique) # remove same variables
interaction_length <- sapply(interaction_list, length)
interaction_length <- lengths(interaction_list)
interaction_list <- interaction_list[interaction_length > 1]
interaction_list <- unique(lapply(interaction_list, sort))
return(interaction_list)

View File

@ -189,7 +189,7 @@ test_that("SHAPs sum to predictions, with or without DART", {
tol <- 1e-5
expect_equal(rowSums(shap), pred, tol = tol)
expect_equal(apply(shapi, 1, sum), pred, tol = tol)
expect_equal(rowSums(shapi), pred, tol = tol)
for (i in seq_len(nrow(d)))
for (f in list(rowSums, colSums))
expect_equal(f(shapi[i, , ]), shap[i, ], tol = tol)

View File

@ -20,15 +20,23 @@ my_linters <- list(
any_duplicated = lintr::any_duplicated_linter(),
any_is_na = lintr::any_is_na_linter(),
assignment_linter = lintr::assignment_linter(),
boolean_arithmetic = lintr::boolean_arithmetic_linter(),
brace_linter = lintr::brace_linter(),
class_equals = lintr::class_equals_linter(),
commas_linter = lintr::commas_linter(),
empty_assignment = lintr::empty_assignment_linter(),
equals_na = lintr::equals_na_linter(),
fixed_regex = lintr::fixed_regex_linter(),
for_loop_index = lintr::for_loop_index_linter(),
function_return = lintr::function_return_linter(),
infix_spaces_linter = lintr::infix_spaces_linter(),
is_numeric = lintr::is_numeric_linter(),
line_length_linter = lintr::line_length_linter(length = 150L),
no_tab_linter = lintr::no_tab_linter(),
lengths = lintr::lengths_linter(),
matrix = lintr::matrix_apply_linter(),
object_usage_linter = lintr::object_usage_linter(),
object_length_linter = lintr::object_length_linter(),
routine_registration = lintr::routine_registration_linter(),
semicolon = lintr::semicolon_linter(),
seq = lintr::seq_linter(),
spaces_inside_linter = lintr::spaces_inside_linter(),
@ -37,9 +45,10 @@ my_linters <- list(
trailing_blank_lines_linter = lintr::trailing_blank_lines_linter(),
trailing_whitespace_linter = lintr::trailing_whitespace_linter(),
true_false = lintr::T_and_F_symbol_linter(),
unneeded_concatenation = lintr::unneeded_concatenation_linter(),
unnecessary_concatenation = lintr::unnecessary_concatenation_linter(),
unreachable_code = lintr::unreachable_code_linter(),
vector_logic = lintr::vector_logic_linter()
vector_logic = lintr::vector_logic_linter(),
whitespace = lintr::whitespace_linter()
)
noquote(paste0(length(FILES_TO_LINT), " R files need linting"))