[R] [CI] enforce lintr::function_left_parentheses_linter check (#9631)

This commit is contained in:
James Lamb
2023-10-07 20:42:09 -05:00
committed by GitHub
parent 4d7a187cb0
commit 799f8485e2
14 changed files with 33 additions and 32 deletions

View File

@@ -19,15 +19,15 @@ w <- runif(metadata$kRows)
version <- packageVersion('xgboost')
target_dir <- 'models'
save_booster <- function (booster, model_name) {
booster_bin <- function (model_name) {
return (file.path(target_dir, paste('xgboost-', version, '.', model_name, '.bin', sep = '')))
save_booster <- function(booster, model_name) {
booster_bin <- function(model_name) {
return(file.path(target_dir, paste('xgboost-', version, '.', model_name, '.bin', sep = '')))
}
booster_json <- function (model_name) {
return (file.path(target_dir, paste('xgboost-', version, '.', model_name, '.json', sep = '')))
booster_json <- function(model_name) {
return(file.path(target_dir, paste('xgboost-', version, '.', model_name, '.json', sep = '')))
}
booster_rds <- function (model_name) {
return (file.path(target_dir, paste('xgboost-', version, '.', model_name, '.rds', sep = '')))
booster_rds <- function(model_name) {
return(file.path(target_dir, paste('xgboost-', version, '.', model_name, '.rds', sep = '')))
}
xgb.save(booster, booster_bin(model_name))
saveRDS(booster, booster_rds(model_name))
@@ -36,7 +36,7 @@ save_booster <- function (booster, model_name) {
}
}
generate_regression_model <- function () {
generate_regression_model <- function() {
print('Regression')
y <- rnorm(metadata$kRows)
@@ -47,7 +47,7 @@ generate_regression_model <- function () {
save_booster(booster, 'reg')
}
generate_logistic_model <- function () {
generate_logistic_model <- function() {
print('Binary classification with logistic loss')
y <- sample(0:1, size = metadata$kRows, replace = TRUE)
stopifnot(max(y) == 1, min(y) == 0)
@@ -64,7 +64,7 @@ generate_logistic_model <- function () {
}
}
generate_classification_model <- function () {
generate_classification_model <- function() {
print('Multi-class classification')
y <- sample(0:(metadata$kClasses - 1), size = metadata$kRows, replace = TRUE)
stopifnot(max(y) == metadata$kClasses - 1, min(y) == 0)
@@ -77,7 +77,7 @@ generate_classification_model <- function () {
save_booster(booster, 'cls')
}
generate_ranking_model <- function () {
generate_ranking_model <- function() {
print('Learning to rank')
y <- sample(0:4, size = metadata$kRows, replace = TRUE)
stopifnot(max(y) == 4, min(y) == 0)

View File

@@ -9,20 +9,20 @@ metadata <- list(
kClasses = 3
)
run_model_param_check <- function (config) {
run_model_param_check <- function(config) {
testthat::expect_equal(config$learner$learner_model_param$num_feature, '4')
testthat::expect_equal(config$learner$learner_train_param$booster, 'gbtree')
}
get_num_tree <- function (booster) {
get_num_tree <- function(booster) {
dump <- xgb.dump(booster)
m <- regexec('booster\\[[0-9]+\\]', dump, perl = TRUE)
m <- regmatches(dump, m)
num_tree <- Reduce('+', lapply(m, length))
return (num_tree)
return(num_tree)
}
run_booster_check <- function (booster, name) {
run_booster_check <- function(booster, name) {
# If given a handle, we need to call xgb.Booster.complete() prior to using xgb.config().
if (inherits(booster, "xgb.Booster") && xgboost:::is.null.handle(booster$handle)) {
booster <- xgb.Booster.complete(booster)
@@ -68,7 +68,7 @@ test_that("Models from previous versions of XGBoost can be loaded", {
pred_data <- xgb.DMatrix(matrix(c(0, 0, 0, 0), nrow = 1, ncol = 4), nthread = 2)
lapply(list.files(model_dir), function (x) {
lapply(list.files(model_dir), function(x) {
model_file <- file.path(model_dir, x)
m <- regexec("xgboost-([0-9\\.]+)\\.([a-z]+)\\.[a-z]+", model_file, perl = TRUE)
m <- regmatches(model_file, m)[[1]]

View File

@@ -47,7 +47,7 @@ test_that('Test ranking with weighted data', {
pred <- predict(bst, newdata = dtrain, ntreelimit = i)
# is_sorted[i]: is i-th group correctly sorted by the ranking predictor?
is_sorted <- lapply(seq(1, 20, by = 5),
function (k) {
function(k) {
ind <- order(-pred[k:(k + 4)])
z <- y[ind + (k - 1)]
all(diff(z) <= 0) # Check if z is monotone decreasing