[R] fix uses of 1:length(x) and other small things (#5992)

This commit is contained in:
James Lamb
2020-08-08 20:31:33 +01:00
committed by GitHub
parent 801e6b6800
commit 589b385ec6
7 changed files with 15 additions and 15 deletions

View File

@@ -99,7 +99,7 @@ test_that("xgb.DMatrix: colnames", {
dtest <- xgb.DMatrix(test_data, label = test_label)
expect_equal(colnames(dtest), colnames(test_data))
expect_error(colnames(dtest) <- 'asdf')
new_names <- make.names(1:ncol(test_data))
new_names <- make.names(seq_len(ncol(test_data)))
expect_silent(colnames(dtest) <- new_names)
expect_equal(colnames(dtest), new_names)
expect_silent(colnames(dtest) <- NULL)

View File

@@ -174,7 +174,7 @@ test_that("SHAPs sum to predictions, with or without DART", {
expect_equal(rowSums(shap), pred, tol = tol)
expect_equal(apply(shapi, 1, sum), pred, tol = tol)
for (i in 1 : nrow(d))
for (i in seq_len(nrow(d)))
for (f in list(rowSums, colSums))
expect_equal(f(shapi[i, , ]), shap[i, ], tol = tol)
}