[R] [CI] add more linting checks (#8624)

This commit is contained in:
James Lamb 2022-12-29 04:20:36 -06:00 committed by GitHub
parent b05abfc494
commit 9a98c3726c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 5 deletions

View File

@ -328,7 +328,6 @@ setinfo.xgb.DMatrix <- function(object, name, info, ...) {
return(TRUE) return(TRUE)
} }
stop("setinfo: unknown info name ", name) stop("setinfo: unknown info name ", name)
return(FALSE)
} }
@ -418,7 +417,7 @@ print.xgb.DMatrix <- function(x, verbose = FALSE, ...) {
cat(infos) cat(infos)
cnames <- colnames(x) cnames <- colnames(x)
cat(' colnames:') cat(' colnames:')
if (verbose & !is.null(cnames)) { if (verbose && !is.null(cnames)) {
cat("\n'") cat("\n'")
cat(cnames, sep = "','") cat(cnames, sep = "','")
cat("'") cat("'")

View File

@ -143,7 +143,7 @@ xgb.plot.shap <- function(data, shap_contrib = NULL, features = NULL, top_n = 1,
y <- shap_contrib[, f][ord] y <- shap_contrib[, f][ord]
x_lim <- range(x, na.rm = TRUE) x_lim <- range(x, na.rm = TRUE)
y_lim <- range(y, na.rm = TRUE) y_lim <- range(y, na.rm = TRUE)
do_na <- plot_NA && any(is.na(x)) do_na <- plot_NA && anyNA(x)
if (do_na) { if (do_na) {
x_range <- diff(x_lim) x_range <- diff(x_lim)
loc_na <- min(x, na.rm = TRUE) + x_range * pos_NA loc_na <- min(x, na.rm = TRUE) + x_range * pos_NA
@ -272,7 +272,7 @@ xgb.shap.data <- function(data, shap_contrib = NULL, features = NULL, top_n = 1,
imp <- xgb.importance(model = model, trees = trees, feature_names = colnames(data)) imp <- xgb.importance(model = model, trees = trees, feature_names = colnames(data))
} }
top_n <- top_n[1] top_n <- top_n[1]
if (top_n < 1 | top_n > 100) stop("top_n: must be an integer within [1, 100]") if (top_n < 1 || top_n > 100) stop("top_n: must be an integer within [1, 100]")
features <- imp$Feature[seq_len(min(top_n, NROW(imp)))] features <- imp$Feature[seq_len(min(top_n, NROW(imp)))]
} }
if (is.character(features)) { if (is.character(features)) {

View File

@ -17,6 +17,8 @@ FILES_TO_LINT <- list.files(
my_linters <- list( my_linters <- list(
absolute_path_linter = lintr::absolute_path_linter(), absolute_path_linter = lintr::absolute_path_linter(),
any_duplicated = lintr::any_duplicated_linter(),
any_is_na = lintr::any_is_na_linter(),
assignment_linter = lintr::assignment_linter(), assignment_linter = lintr::assignment_linter(),
brace_linter = lintr::brace_linter(), brace_linter = lintr::brace_linter(),
commas_linter = lintr::commas_linter(), commas_linter = lintr::commas_linter(),
@ -30,10 +32,13 @@ my_linters <- list(
seq = lintr::seq_linter(), seq = lintr::seq_linter(),
spaces_inside_linter = lintr::spaces_inside_linter(), spaces_inside_linter = lintr::spaces_inside_linter(),
spaces_left_parentheses_linter = lintr::spaces_left_parentheses_linter(), spaces_left_parentheses_linter = lintr::spaces_left_parentheses_linter(),
sprintf = lintr::sprintf_linter(),
trailing_blank_lines_linter = lintr::trailing_blank_lines_linter(), trailing_blank_lines_linter = lintr::trailing_blank_lines_linter(),
trailing_whitespace_linter = lintr::trailing_whitespace_linter(), trailing_whitespace_linter = lintr::trailing_whitespace_linter(),
true_false = lintr::T_and_F_symbol_linter(), true_false = lintr::T_and_F_symbol_linter(),
unneeded_concatenation = lintr::unneeded_concatenation_linter() unneeded_concatenation = lintr::unneeded_concatenation_linter(),
unreachable_code = lintr::unreachable_code_linter(),
vector_logic = lintr::vector_logic_linter()
) )
noquote(paste0(length(FILES_TO_LINT), " R files need linting")) noquote(paste0(length(FILES_TO_LINT), " R files need linting"))