[R] prefer startsWith to substr() or regular expressions (#10687)
This commit is contained in:
parent
fb9201abae
commit
18b28d9315
@ -104,7 +104,7 @@ check.booster.params <- function(params, ...) {
|
|||||||
|
|
||||||
# for multiclass, expect num_class to be set
|
# for multiclass, expect num_class to be set
|
||||||
if (typeof(params[['objective']]) == "character" &&
|
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) {
|
as.numeric(NVL(params[['num_class']], 0)) < 2) {
|
||||||
stop("'num_class' > 1 parameter must be set for multiclass classification")
|
stop("'num_class' > 1 parameter must be set for multiclass classification")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -109,7 +109,7 @@ xgb.model.dt.tree <- function(model = NULL, text = NULL,
|
|||||||
} else {
|
} else {
|
||||||
trees <- trees[trees >= 0 & trees <= max(td$Tree)]
|
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))]
|
td[, Node := as.integer(sub("^([0-9]+):.*", "\\1", t))]
|
||||||
if (!use_int_id) td[, ID := add.tree.id(Node, Tree)]
|
if (!use_int_id) td[, ID := add.tree.id(Node, Tree)]
|
||||||
|
|||||||
@ -43,6 +43,7 @@ my_linters <- list(
|
|||||||
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(),
|
sprintf = lintr::sprintf_linter(),
|
||||||
|
string_boundary = lintr::string_boundary_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(),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user