From 9a98c3726cf7c91bce11b18ff21eca694d6e813f Mon Sep 17 00:00:00 2001 From: James Lamb Date: Thu, 29 Dec 2022 04:20:36 -0600 Subject: [PATCH] [R] [CI] add more linting checks (#8624) --- R-package/R/xgb.DMatrix.R | 3 +-- R-package/R/xgb.plot.shap.R | 4 ++-- tests/ci_build/lint_r.R | 7 ++++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/R-package/R/xgb.DMatrix.R b/R-package/R/xgb.DMatrix.R index 71c1af1ab..0a2c45dbf 100644 --- a/R-package/R/xgb.DMatrix.R +++ b/R-package/R/xgb.DMatrix.R @@ -328,7 +328,6 @@ setinfo.xgb.DMatrix <- function(object, name, info, ...) { return(TRUE) } stop("setinfo: unknown info name ", name) - return(FALSE) } @@ -418,7 +417,7 @@ print.xgb.DMatrix <- function(x, verbose = FALSE, ...) { cat(infos) cnames <- colnames(x) cat(' colnames:') - if (verbose & !is.null(cnames)) { + if (verbose && !is.null(cnames)) { cat("\n'") cat(cnames, sep = "','") cat("'") diff --git a/R-package/R/xgb.plot.shap.R b/R-package/R/xgb.plot.shap.R index 7899dea7a..581f61dba 100644 --- a/R-package/R/xgb.plot.shap.R +++ b/R-package/R/xgb.plot.shap.R @@ -143,7 +143,7 @@ xgb.plot.shap <- function(data, shap_contrib = NULL, features = NULL, top_n = 1, y <- shap_contrib[, f][ord] x_lim <- range(x, 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) { x_range <- diff(x_lim) 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)) } 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)))] } if (is.character(features)) { diff --git a/tests/ci_build/lint_r.R b/tests/ci_build/lint_r.R index 43ede3cf3..6c3e81773 100644 --- a/tests/ci_build/lint_r.R +++ b/tests/ci_build/lint_r.R @@ -17,6 +17,8 @@ FILES_TO_LINT <- list.files( my_linters <- list( 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(), brace_linter = lintr::brace_linter(), commas_linter = lintr::commas_linter(), @@ -30,10 +32,13 @@ my_linters <- list( seq = lintr::seq_linter(), spaces_inside_linter = lintr::spaces_inside_linter(), spaces_left_parentheses_linter = lintr::spaces_left_parentheses_linter(), + sprintf = lintr::sprintf_linter(), 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() + 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"))