Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R] [ci] R linters are not being run in CI #5796

Closed
jameslamb opened this issue Jun 16, 2020 · 12 comments · Fixed by #5944
Closed

[R] [ci] R linters are not being run in CI #5796

jameslamb opened this issue Jun 16, 2020 · 12 comments · Fixed by #5944
Assignees

Comments

@jameslamb
Copy link
Contributor

jameslamb commented Jun 16, 2020

I tried to pick up part of #5779 tonight, and realized something...I believe that the R linting tests are not being run in CI.

I confirmed this by copying those linters used in test_lint.R into the following script

lintr script (click me)
library(lintr)

args <- commandArgs(
    trailingOnly = TRUE
)
SOURCE_DIR <- args[[1L]]

FILES_TO_LINT <- list.files(
    path = SOURCE_DIR
    , pattern = "\\.r$"
    , all.files = TRUE
    , ignore.case = TRUE
    , full.names = TRUE
    , recursive = TRUE
    , include.dirs = FALSE
)

LINTERS_TO_USE <- list(
    absolute_paths_linter=lintr::absolute_paths_linter
    , assignment_linter=lintr::assignment_linter
    , closed_curly_linter=lintr::closed_curly_linter
    , commas_linter=lintr::commas_linter
    , infix_spaces_linter=lintr::infix_spaces_linter
    , line_length_linter=lintr::line_length_linter
    , no_tab_linter=lintr::no_tab_linter
    , object_usage_linter=lintr::object_usage_linter
    , object_length_linter=lintr::object_length_linter
    , open_curly_linter=lintr::open_curly_linter
    , spaces_inside_linter=lintr::spaces_inside_linter
    , spaces_left_parentheses_linter=lintr::spaces_left_parentheses_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
)

cat(sprintf("Found %i R files to lint\n", length(FILES_TO_LINT)))

results <- NULL

for (r_file in FILES_TO_LINT) {

    this_result <- lintr::lint(
        filename = r_file
        , linters = LINTERS_TO_USE
        , cache = FALSE
    )

    print(
        sprintf(
            "Found %i linting errors in %s"
            , length(this_result)
            , r_file
        )
        , quote = FALSE
    )

    results <- c(results, this_result)

}

issues_found <- length(results)

if (issues_found > 0L) {
    print(results)
}

quit(save = "no", status = issues_found)

And then running it like this

Rscript lintr_r_code.R $(pwd)/R-package

I think the issue is that test_lint.R includes a skip_on_cran()

And R tests are run by building a package and using R CMD check --as-cran

R.exe CMD check xgboost*.tar.gz --no-manual --no-build-vignettes --as-cran --install-args=--build

When I run the script above, it finds 900+ linting issues.

First 100 R linter issues (click me)
Found 55 R files to lint
[1] Found 30 linting errors in R-package//demo/basic_walkthrough.R
[1] Found 7 linting errors in R-package//demo/boost_from_prediction.R
[1] Found 9 linting errors in R-package//demo/caret_wrapper.R
[1] Found 21 linting errors in R-package//demo/create_sparse_matrix.R
[1] Found 15 linting errors in R-package//demo/cross_validation.R
[1] Found 21 linting errors in R-package//demo/custom_objective.R
[1] Found 9 linting errors in R-package//demo/early_stopping.R
[1] Found 8 linting errors in R-package//demo/generalized_linear_model.R
[1] Found 5 linting errors in R-package//demo/gpu_accelerated.R
[1] Found 73 linting errors in R-package//demo/interaction_constraints.R
[1] Found 15 linting errors in R-package//demo/poisson_regression.R
[1] Found 17 linting errors in R-package//demo/predict_first_ntree.R
[1] Found 13 linting errors in R-package//demo/predict_leaf_indices.R
[1] Found 0 linting errors in R-package//demo/runall.R
[1] Found 7 linting errors in R-package//demo/tweedie_regression.R
[1] Found 0 linting errors in R-package//inst/make-r-def.R
[1] Found 22 linting errors in R-package//R/callbacks.R
[1] Found 14 linting errors in R-package//R/utils.R
[1] Found 23 linting errors in R-package//R/xgb.Booster.R
[1] Found 26 linting errors in R-package//R/xgb.create.features.R
[1] Found 13 linting errors in R-package//R/xgb.cv.R
[1] Found 4 linting errors in R-package//R/xgb.DMatrix.R
[1] Found 4 linting errors in R-package//R/xgb.DMatrix.save.R
[1] Found 14 linting errors in R-package//R/xgb.dump.R
[1] Found 33 linting errors in R-package//R/xgb.ggplot.R
[1] Found 37 linting errors in R-package//R/xgb.importance.R
[1] Found 0 linting errors in R-package//R/xgb.load.R
[1] Found 0 linting errors in R-package//R/xgb.load.raw.R
[1] Found 48 linting errors in R-package//R/xgb.model.dt.tree.R
[1] Found 31 linting errors in R-package//R/xgb.plot.deepness.R
[1] Found 2 linting errors in R-package//R/xgb.plot.importance.R
[1] Found 21 linting errors in R-package//R/xgb.plot.multi.trees.R
[1] Found 9 linting errors in R-package//R/xgb.plot.shap.R
[1] Found 26 linting errors in R-package//R/xgb.plot.tree.R
[1] Found 14 linting errors in R-package//R/xgb.save.R
[1] Found 0 linting errors in R-package//R/xgb.save.raw.R
[1] Found 1 linting errors in R-package//R/xgb.serialize.R
[1] Found 6 linting errors in R-package//R/xgb.train.R
[1] Found 1 linting errors in R-package//R/xgb.unserialize.R
[1] Found 0 linting errors in R-package//R/xgboost.R
[1] Found 0 linting errors in R-package//tests/testthat.R
[1] Found 61 linting errors in R-package//tests/testthat/test_basic.R
[1] Found 44 linting errors in R-package//tests/testthat/test_callbacks.R
[1] Found 13 linting errors in R-package//tests/testthat/test_custom_objective.R
[1] Found 22 linting errors in R-package//tests/testthat/test_dmatrix.R
[1] Found 2 linting errors in R-package//tests/testthat/test_gc_safety.R
[1] Found 4 linting errors in R-package//tests/testthat/test_glm.R
[1] Found 38 linting errors in R-package//tests/testthat/test_helpers.R
[1] Found 29 linting errors in R-package//tests/testthat/test_interaction_constraints.R
[1] Found 57 linting errors in R-package//tests/testthat/test_interactions.R
[1] Found 16 linting errors in R-package//tests/testthat/test_lint.R
[1] Found 13 linting errors in R-package//tests/testthat/test_monotone.R
[1] Found 2 linting errors in R-package//tests/testthat/test_parameter_exposure.R
[1] Found 7 linting errors in R-package//tests/testthat/test_poisson_regression.R
[1] Found 11 linting errors in R-package//tests/testthat/test_update.R
[[1]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:6:29: style: Put spaces around all infix operators.
data(agaricus.train, package='xgboost')
                           ~^~

[[2]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:7:28: style: Put spaces around all infix operators.
data(agaricus.test, package='xgboost')
                          ~^~

[[3]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:29:80: style: Trailing whitespace is superfluous.
bst <- xgboost(data = dtrain, max_depth = 2, eta = 1, nrounds = 2, nthread = 2, 
                                                                               ^

[[4]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:49:54: style: Trailing whitespace is superfluous.
# you can put in Matrix, sparseMatrix, or xgb.DMatrix 
                                                     ^

[[5]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:61:51: style: Put spaces around all infix operators.
print(paste("sum(abs(pred2-pred))=", sum(abs(pred2-pred))))
                                                 ~^~

[[6]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:64:5: style: Use <-, not =, for assignment.
raw = xgb.save.raw(bst)
    ^

[[7]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:69:51: style: Put spaces around all infix operators.
print(paste("sum(abs(pred3-pred))=", sum(abs(pred3-pred))))
                                                 ~^~

[[8]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:73:47: style: Put spaces around all infix operators.
dtrain <- xgb.DMatrix(data = train$data, label=train$label)
                                             ~^~

[[9]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:74:45: style: Put spaces around all infix operators.
dtest <- xgb.DMatrix(data = test$data, label=test$label)
                                           ~^~

[[10]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:77:24: style: Put spaces around all infix operators.
watchlist <- list(train=dtrain, test=dtest)
                      ~^~

[[11]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:77:37: style: Put spaces around all infix operators.
watchlist <- list(train=dtrain, test=dtest)
                                   ~^~

[[12]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:79:79: style: Trailing whitespace is superfluous.
# watchlist allows us to monitor the evaluation result on all data in the list 
                                                                              ^

[[13]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:81:22: style: Put spaces around all infix operators.
bst <- xgb.train(data=dtrain, max_depth=2, eta=1, nrounds=2, watchlist=watchlist,
                    ~^~

[[14]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:81:40: style: Put spaces around all infix operators.
bst <- xgb.train(data=dtrain, max_depth=2, eta=1, nrounds=2, watchlist=watchlist,
                                      ~^~

[[15]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:81:47: style: Put spaces around all infix operators.
bst <- xgb.train(data=dtrain, max_depth=2, eta=1, nrounds=2, watchlist=watchlist,
                                             ~^~

[[16]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:81:58: style: Put spaces around all infix operators.
bst <- xgb.train(data=dtrain, max_depth=2, eta=1, nrounds=2, watchlist=watchlist,
                                                        ~^~

[[17]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:81:71: style: Put spaces around all infix operators.
bst <- xgb.train(data=dtrain, max_depth=2, eta=1, nrounds=2, watchlist=watchlist,
                                                                     ~^~

[[18]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:85:22: style: Put spaces around all infix operators.
bst <- xgb.train(data=dtrain, max_depth=2, eta=1, nrounds=2, watchlist=watchlist,
                    ~^~

[[19]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:85:40: style: Put spaces around all infix operators.
bst <- xgb.train(data=dtrain, max_depth=2, eta=1, nrounds=2, watchlist=watchlist,
                                      ~^~

[[20]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:85:47: style: Put spaces around all infix operators.
bst <- xgb.train(data=dtrain, max_depth=2, eta=1, nrounds=2, watchlist=watchlist,
                                             ~^~

[[21]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:85:58: style: Put spaces around all infix operators.
bst <- xgb.train(data=dtrain, max_depth=2, eta=1, nrounds=2, watchlist=watchlist,
                                                        ~^~

[[22]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:85:71: style: Put spaces around all infix operators.
bst <- xgb.train(data=dtrain, max_depth=2, eta=1, nrounds=2, watchlist=watchlist,
                                                                     ~^~

[[23]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:93:22: style: Put spaces around all infix operators.
bst <- xgb.train(data=dtrain2, max_depth=2, eta=1, nrounds=2, watchlist=watchlist,
                    ~^~

[[24]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:93:41: style: Put spaces around all infix operators.
bst <- xgb.train(data=dtrain2, max_depth=2, eta=1, nrounds=2, watchlist=watchlist,
                                       ~^~

[[25]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:93:48: style: Put spaces around all infix operators.
bst <- xgb.train(data=dtrain2, max_depth=2, eta=1, nrounds=2, watchlist=watchlist,
                                              ~^~

[[26]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:93:59: style: Put spaces around all infix operators.
bst <- xgb.train(data=dtrain2, max_depth=2, eta=1, nrounds=2, watchlist=watchlist,
                                                         ~^~

[[27]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:93:72: style: Put spaces around all infix operators.
bst <- xgb.train(data=dtrain2, max_depth=2, eta=1, nrounds=2, watchlist=watchlist,
                                                                      ~^~

[[28]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:96:7: style: Use <-, not =, for assignment.
label = getinfo(dtest, "label")
      ^

[[29]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:98:56: style: Put spaces around all infix operators.
err <- as.numeric(sum(as.integer(pred > 0.5) != label))/length(label)
                                                      ~^~

[[30]]
/Users/jlamb/repos/xgboost/R-package/demo/basic_walkthrough.R:102:11: style: Use <-, not =, for assignment.
dump_path = file.path(tempdir(), 'dump.raw.txt')
          ^

[[31]]
/Users/jlamb/repos/xgboost/R-package/demo/boost_from_prediction.R:3:29: style: Put spaces around all infix operators.
data(agaricus.train, package='xgboost')
                           ~^~

[[32]]
/Users/jlamb/repos/xgboost/R-package/demo/boost_from_prediction.R:4:28: style: Put spaces around all infix operators.
data(agaricus.test, package='xgboost')
                          ~^~

[[33]]
/Users/jlamb/repos/xgboost/R-package/demo/boost_from_prediction.R:14:24: style: Put spaces around all infix operators.
param <- list(max_depth=2, eta=1, nthread = 2, objective='binary:logistic')
                      ~^~

[[34]]
/Users/jlamb/repos/xgboost/R-package/demo/boost_from_prediction.R:14:31: style: Put spaces around all infix operators.
param <- list(max_depth=2, eta=1, nthread = 2, objective='binary:logistic')
                             ~^~

[[35]]
/Users/jlamb/repos/xgboost/R-package/demo/boost_from_prediction.R:14:57: style: Put spaces around all infix operators.
param <- list(max_depth=2, eta=1, nthread = 2, objective='binary:logistic')
                                                       ~^~

[[36]]
/Users/jlamb/repos/xgboost/R-package/demo/boost_from_prediction.R:18:44: style: Put spaces around all infix operators.
ptrain <- predict(bst, dtrain, outputmargin=TRUE)
                                          ~^~

[[37]]
/Users/jlamb/repos/xgboost/R-package/demo/boost_from_prediction.R:19:43: style: Put spaces around all infix operators.
ptest  <- predict(bst, dtest, outputmargin=TRUE)
                                         ~^~

[[38]]
/Users/jlamb/repos/xgboost/R-package/demo/caret_wrapper.R:2:51: style: Trailing whitespace is superfluous.
devtools::install_github("topepo/caret/pkg/caret") 
                                                  ^

[[39]]
/Users/jlamb/repos/xgboost/R-package/demo/caret_wrapper.R:16:5: style: Commas should always have a space after.
df[,AgeDiscret:= as.factor(round(Age/10,0))]
    ^

[[40]]
/Users/jlamb/repos/xgboost/R-package/demo/caret_wrapper.R:16:15: style: Put spaces around all infix operators.
df[,AgeDiscret:= as.factor(round(Age/10,0))]
             ~^

[[41]]
/Users/jlamb/repos/xgboost/R-package/demo/caret_wrapper.R:16:37: style: Put spaces around all infix operators.
df[,AgeDiscret:= as.factor(round(Age/10,0))]
                                   ~^~

[[42]]
/Users/jlamb/repos/xgboost/R-package/demo/caret_wrapper.R:16:41: style: Commas should always have a space after.
df[,AgeDiscret:= as.factor(round(Age/10,0))]
                                        ^

[[43]]
/Users/jlamb/repos/xgboost/R-package/demo/caret_wrapper.R:19:5: style: Commas should always have a space after.
df[,AgeCat:= as.factor(ifelse(Age > 30, "Old", "Young"))]
    ^

[[44]]
/Users/jlamb/repos/xgboost/R-package/demo/caret_wrapper.R:19:11: style: Put spaces around all infix operators.
df[,AgeCat:= as.factor(ifelse(Age > 30, "Old", "Young"))]
         ~^

[[45]]
/Users/jlamb/repos/xgboost/R-package/demo/caret_wrapper.R:22:5: style: Commas should always have a space after.
df[,ID:=NULL]
    ^

[[46]]
/Users/jlamb/repos/xgboost/R-package/demo/caret_wrapper.R:22:7: style: Put spaces around all infix operators.
df[,ID:=NULL]
     ~^~~

[[47]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:9:66: style: Trailing whitespace is superfluous.
# Sometimes the dataset we have to work on have categorical data. 
                                                                 ^

[[48]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:12:47: style: Trailing whitespace is superfluous.
# In R, categorical variable is called Factor. 
                                              ^

[[49]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:35:5: style: Commas should always have a space after.
df[,AgeDiscret:= as.factor(round(Age/10,0))]
    ^

[[50]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:35:15: style: Put spaces around all infix operators.
df[,AgeDiscret:= as.factor(round(Age/10,0))]
             ~^

[[51]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:35:37: style: Put spaces around all infix operators.
df[,AgeDiscret:= as.factor(round(Age/10,0))]
                                   ~^~

[[52]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:35:41: style: Commas should always have a space after.
df[,AgeDiscret:= as.factor(round(Age/10,0))]
                                        ^

[[53]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:38:5: style: Commas should always have a space after.
df[,AgeCat:= as.factor(ifelse(Age > 30, "Old", "Young"))]
    ^

[[54]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:38:11: style: Put spaces around all infix operators.
df[,AgeCat:= as.factor(ifelse(Age > 30, "Old", "Young"))]
         ~^

[[55]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:41:5: style: Commas should always have a space after.
df[,ID:=NULL]
    ^

[[56]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:41:7: style: Put spaces around all infix operators.
df[,ID:=NULL]
     ~^~~

[[57]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:45:18: style: Commas should always have a space after.
print(levels(df[,Treatment]))
                 ^

[[58]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:55:15: style: Use <-, not =, for assignment.
sparse_matrix = sparse.model.matrix(Improved~.-1, data = df)
              ^

[[59]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:55:47: style: Put spaces around all infix operators.
sparse_matrix = sparse.model.matrix(Improved~.-1, data = df)
                                             ~^~

[[60]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:61:48: style: Trailing whitespace is superfluous.
# 1. Set, for all rows, field in Y column to 0; 
                                               ^

[[61]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:62:41: style: Trailing whitespace is superfluous.
# 2. set Y to 1 when Improved == Marked; 
                                        ^

[[62]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:64:15: style: Use <-, not =, for assignment.
output_vector = df[,Y:=0][Improved == "Marked",Y:=1][,Y]
              ^

[[63]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:64:21: style: Commas should always have a space after.
output_vector = df[,Y:=0][Improved == "Marked",Y:=1][,Y]
                    ^

[[64]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:64:22: style: Put spaces around all infix operators.
output_vector = df[,Y:=0][Improved == "Marked",Y:=1][,Y]
                    ~^~~

[[65]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:64:48: style: Commas should always have a space after.
output_vector = df[,Y:=0][Improved == "Marked",Y:=1][,Y]
                                               ^

[[66]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:64:49: style: Put spaces around all infix operators.
output_vector = df[,Y:=0][Improved == "Marked",Y:=1][,Y]
                                               ~^~~

[[67]]
/Users/jlamb/repos/xgboost/R-package/demo/create_sparse_matrix.R:64:55: style: Commas should always have a space after.
output_vector = df[,Y:=0][Improved == "Marked",Y:=1][,Y]
                                                      ^

[[68]]
/Users/jlamb/repos/xgboost/R-package/demo/cross_validation.R:3:29: style: Put spaces around all infix operators.
data(agaricus.train, package='xgboost')
                           ~^~

[[69]]
/Users/jlamb/repos/xgboost/R-package/demo/cross_validation.R:4:28: style: Put spaces around all infix operators.
data(agaricus.test, package='xgboost')
                          ~^~

[[70]]
/Users/jlamb/repos/xgboost/R-package/demo/cross_validation.R:9:24: style: Put spaces around all infix operators.
param <- list(max_depth=2, eta=1, nthread=2, objective='binary:logistic')
                      ~^~

[[71]]
/Users/jlamb/repos/xgboost/R-package/demo/cross_validation.R:9:31: style: Put spaces around all infix operators.
param <- list(max_depth=2, eta=1, nthread=2, objective='binary:logistic')
                             ~^~

[[72]]
/Users/jlamb/repos/xgboost/R-package/demo/cross_validation.R:9:42: style: Put spaces around all infix operators.
param <- list(max_depth=2, eta=1, nthread=2, objective='binary:logistic')
                                        ~^~

[[73]]
/Users/jlamb/repos/xgboost/R-package/demo/cross_validation.R:9:55: style: Put spaces around all infix operators.
param <- list(max_depth=2, eta=1, nthread=2, objective='binary:logistic')
                                                     ~^~

[[74]]
/Users/jlamb/repos/xgboost/R-package/demo/cross_validation.R:15:37: style: Put spaces around all infix operators.
xgb.cv(param, dtrain, nrounds, nfold=5, metrics={'error'})
                                   ~^~

[[75]]
/Users/jlamb/repos/xgboost/R-package/demo/cross_validation.R:15:48: style: Put spaces around all infix operators.
xgb.cv(param, dtrain, nrounds, nfold=5, metrics={'error'})
                                              ~^~

[[76]]
/Users/jlamb/repos/xgboost/R-package/demo/cross_validation.R:21:37: style: Put spaces around all infix operators.
xgb.cv(param, dtrain, nrounds, nfold=5,
                                   ~^~

[[77]]
/Users/jlamb/repos/xgboost/R-package/demo/cross_validation.R:22:15: style: Put spaces around all infix operators.
       metrics='error', showsd = FALSE)
             ~^~

[[78]]
/Users/jlamb/repos/xgboost/R-package/demo/cross_validation.R:32:13: style: Put spaces around all infix operators.
  preds <- 1/(1 + exp(-preds))
           ~^~

[[79]]
/Users/jlamb/repos/xgboost/R-package/demo/cross_validation.R:32:14: style: Place a space before left parenthesis, except in a function call.
  preds <- 1/(1 + exp(-preds))
             ^

[[80]]
/Users/jlamb/repos/xgboost/R-package/demo/cross_validation.R:39:48: style: Put spaces around all infix operators.
  err <- as.numeric(sum(labels != (preds > 0)))/length(labels)
                                              ~^~

[[81]]
/Users/jlamb/repos/xgboost/R-package/demo/cross_validation.R:43:24: style: Put spaces around all infix operators.
param <- list(max_depth=2, eta=1,
                      ~^~

[[82]]
/Users/jlamb/repos/xgboost/R-package/demo/cross_validation.R:43:31: style: Put spaces around all infix operators.
param <- list(max_depth=2, eta=1,
                             ~^~

[[83]]
/Users/jlamb/repos/xgboost/R-package/demo/custom_objective.R:3:29: style: Put spaces around all infix operators.
data(agaricus.train, package='xgboost')
                           ~^~

[[84]]
/Users/jlamb/repos/xgboost/R-package/demo/custom_objective.R:4:28: style: Put spaces around all infix operators.
data(agaricus.test, package='xgboost')
                          ~^~

[[85]]
/Users/jlamb/repos/xgboost/R-package/demo/custom_objective.R:18:13: style: Put spaces around all infix operators.
  preds <- 1/(1 + exp(-preds))
           ~^~

[[86]]
/Users/jlamb/repos/xgboost/R-package/demo/custom_objective.R:18:14: style: Place a space before left parenthesis, except in a function call.
  preds <- 1/(1 + exp(-preds))
             ^

[[87]]
/Users/jlamb/repos/xgboost/R-package/demo/custom_objective.R:32:48: style: Put spaces around all infix operators.
  err <- as.numeric(sum(labels != (preds > 0)))/length(labels)
                                              ~^~

[[88]]
/Users/jlamb/repos/xgboost/R-package/demo/custom_objective.R:36:24: style: Put spaces around all infix operators.
param <- list(max_depth=2, eta=1, nthread = 2, verbosity=0, 
                      ~^~

[[89]]
/Users/jlamb/repos/xgboost/R-package/demo/custom_objective.R:36:31: style: Put spaces around all infix operators.
param <- list(max_depth=2, eta=1, nthread = 2, verbosity=0, 
                             ~^~

[[90]]
/Users/jlamb/repos/xgboost/R-package/demo/custom_objective.R:36:57: style: Put spaces around all infix operators.
param <- list(max_depth=2, eta=1, nthread = 2, verbosity=0, 
                                                       ~^~

[[91]]
/Users/jlamb/repos/xgboost/R-package/demo/custom_objective.R:36:60: style: Trailing whitespace is superfluous.
param <- list(max_depth=2, eta=1, nthread = 2, verbosity=0, 
                                                           ^

[[92]]
/Users/jlamb/repos/xgboost/R-package/demo/custom_objective.R:37:24: style: Put spaces around all infix operators.
              objective=logregobj, eval_metric=evalerror)
                      ~^~

[[93]]
/Users/jlamb/repos/xgboost/R-package/demo/custom_objective.R:37:47: style: Put spaces around all infix operators.
              objective=logregobj, eval_metric=evalerror)
                                             ~^~

[[94]]
/Users/jlamb/repos/xgboost/R-package/demo/custom_objective.R:44:59: style: Trailing whitespace is superfluous.
# there can be cases where you want additional information 
                                                          ^

[[95]]
/Users/jlamb/repos/xgboost/R-package/demo/custom_objective.R:48:92: style: Trailing whitespace is superfluous.
# set label attribute of dtrain to be label, we use label as an example, it can be anything 
                                                                                           ^

[[96]]
/Users/jlamb/repos/xgboost/R-package/demo/custom_objective.R:55:13: style: Put spaces around all infix operators.
  preds <- 1/(1 + exp(-preds))
           ~^~

[[97]]
/Users/jlamb/repos/xgboost/R-package/demo/custom_objective.R:55:14: style: Place a space before left parenthesis, except in a function call.
  preds <- 1/(1 + exp(-preds))
             ^

[[98]]
/Users/jlamb/repos/xgboost/R-package/demo/custom_objective.R:60:24: style: Put spaces around all infix operators.
param <- list(max_depth=2, eta=1, nthread = 2, verbosity=0, 
                      ~^~

[[99]]
/Users/jlamb/repos/xgboost/R-package/demo/custom_objective.R:60:31: style: Put spaces around all infix operators.
param <- list(max_depth=2, eta=1, nthread = 2, verbosity=0, 
                             ~^~

[[100]]
/Users/jlamb/repos/xgboost/R-package/demo/custom_objective.R:60:57: style: Put spaces around all infix operators.
param <- list(max_depth=2, eta=1, nthread = 2, verbosity=0, 
                                                       ~^~

Proposal for fixing this issue

I think it would be beneficial to move linting out of the R unit tests into a standalone script, like the approach we use in LightGBM

https://github.com/microsoft/LightGBM/blob/4d43e96bbc10de2937aa70a5829977d46bdb1852/.ci/test.sh#L57

If you do that, all skip_* logic can be removed, and it will be really obvious if the tests are not passing.

@jameslamb
Copy link
Contributor Author

@hcho3 would you be open to me submitting a PR that does what I've described (moving linting out of the R unit tests into a standalone script)?

I think it would make sense for me to do that and only include the linters that can impact code correctness (like T_and_F_symbol_linter), and leave it to maintainers to do the ones that will touch a lot more lines for style things like commas, whitespace, etc.

@trivialfis
Copy link
Member

@jameslamb Thanks! That would be great. You don't have to address linting error on the PR, we can follow up by pushing to your branch or open another PR.

@trivialfis
Copy link
Member

I opened a PR for fixing existing linting rules: #5911

@jameslamb
Copy link
Contributor Author

oh nice!

@hcho3 hcho3 closed this as completed Jul 26, 2020
@hcho3
Copy link
Collaborator

hcho3 commented Jul 26, 2020

#5911 added lintr in CI.

@trivialfis trivialfis reopened this Jul 26, 2020
@trivialfis
Copy link
Member

A better script is still needed. Currently I think on github action it shows only you have errors, but not line number.

@hcho3
Copy link
Collaborator

hcho3 commented Jul 26, 2020

@trivialfis I actually noticed this too. I wonder if running lintr in Ubuntu would fix the issue.

@trivialfis
Copy link
Member

I think we need to call lint package explicitly.

@hcho3
Copy link
Collaborator

hcho3 commented Jul 26, 2020

Sure, let me prepare a pull request. I'd like to see clear lintr warnings without having to run it manually.

@jameslamb
Copy link
Contributor Author

it seems that the R linters are not running in CI right now. This is from the most recent build on master (https://github.com/dmlc/xgboost/runs/948472542):

image

I wanted to try fixing some issues found by other linters tonight. Without adding any new linters, I ran this

cd R-package
Rscript tests/run_lint.R

A lot of linting issues were found, and echo $? returns 1

@hcho3
Copy link
Collaborator

hcho3 commented Aug 6, 2020

@jameslamb It looks like GitHub Actions job timed out. I restarted the test. As for the issues, make sure to install XGBoost R package first by running R CMD INSTALL .. Otherwise you will see some bogus issue because R linter won't recognize symbols from XGBoost.

This is from the previous commit of the master branch: https://github.com/dmlc/xgboost/runs/948386277?check_suite_focus=true, where the linter check passed.

@jameslamb
Copy link
Contributor Author

ohhhhh I see! I should have looked at the GitHub Actions config, I see that now. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants