diff --git a/R-package/R/utils.R b/R-package/R/utils.R index 3f67ff23c..d08a411e2 100644 --- a/R-package/R/utils.R +++ b/R-package/R/utils.R @@ -104,7 +104,7 @@ check.booster.params <- function(params, ...) { # for multiclass, expect num_class to be set if (typeof(params[['objective']]) == "character" && - substr(NVL(params[['objective']], 'x'), 1, 6) == 'multi:' && + startsWith(NVL(params[['objective']], 'x'), 'multi:') && as.numeric(NVL(params[['num_class']], 0)) < 2) { stop("'num_class' > 1 parameter must be set for multiclass classification") } diff --git a/R-package/R/xgb.model.dt.tree.R b/R-package/R/xgb.model.dt.tree.R index 73cdecc5c..eb64b1eab 100644 --- a/R-package/R/xgb.model.dt.tree.R +++ b/R-package/R/xgb.model.dt.tree.R @@ -109,7 +109,7 @@ xgb.model.dt.tree <- function(model = NULL, text = NULL, } else { trees <- trees[trees >= 0 & trees <= max(td$Tree)] } - td <- td[Tree %in% trees & !grepl('^booster', t)] + td <- td[Tree %in% trees & !is.na(t) & !startsWith(t, 'booster')] td[, Node := as.integer(sub("^([0-9]+):.*", "\\1", t))] if (!use_int_id) td[, ID := add.tree.id(Node, Tree)] diff --git a/tests/ci_build/lint_r.R b/tests/ci_build/lint_r.R index 9b55ebfce..3d059262e 100644 --- a/tests/ci_build/lint_r.R +++ b/tests/ci_build/lint_r.R @@ -43,6 +43,7 @@ my_linters <- list( spaces_inside_linter = lintr::spaces_inside_linter(), spaces_left_parentheses_linter = lintr::spaces_left_parentheses_linter(), sprintf = lintr::sprintf_linter(), + string_boundary = lintr::string_boundary_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(),