Skip to content

Commit 44bd298

Browse files
authored
[R] remove default values in internal utility functions (#9457)
1 parent 9dbb714 commit 44bd298

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

R-package/R/utils.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ check.custom.eval <- function(env = parent.frame()) {
140140

141141

142142
# Update a booster handle for an iteration with dtrain data
143-
xgb.iter.update <- function(booster_handle, dtrain, iter, obj = NULL) {
143+
xgb.iter.update <- function(booster_handle, dtrain, iter, obj) {
144144
if (!identical(class(booster_handle), "xgb.Booster.handle")) {
145145
stop("booster_handle must be of xgb.Booster.handle class")
146146
}
@@ -163,7 +163,7 @@ xgb.iter.update <- function(booster_handle, dtrain, iter, obj = NULL) {
163163
# Evaluate one iteration.
164164
# Returns a named vector of evaluation metrics
165165
# with the names in a 'datasetname-metricname' format.
166-
xgb.iter.eval <- function(booster_handle, watchlist, iter, feval = NULL) {
166+
xgb.iter.eval <- function(booster_handle, watchlist, iter, feval) {
167167
if (!identical(class(booster_handle), "xgb.Booster.handle"))
168168
stop("class of booster_handle must be xgb.Booster.handle")
169169

@@ -234,7 +234,7 @@ generate.cv.folds <- function(nfold, nrows, stratified, label, params) {
234234
y <- factor(y)
235235
}
236236
}
237-
folds <- xgb.createFolds(y, nfold)
237+
folds <- xgb.createFolds(y = y, k = nfold)
238238
} else {
239239
# make simple non-stratified folds
240240
kstep <- length(rnd_idx) %/% nfold
@@ -251,7 +251,7 @@ generate.cv.folds <- function(nfold, nrows, stratified, label, params) {
251251
# Creates CV folds stratified by the values of y.
252252
# It was borrowed from caret::createFolds and simplified
253253
# by always returning an unnamed list of fold indices.
254-
xgb.createFolds <- function(y, k = 10) {
254+
xgb.createFolds <- function(y, k) {
255255
if (is.numeric(y)) {
256256
## Group the numeric data based on their magnitudes
257257
## and sample within those groups.

R-package/R/xgb.cv.R

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,18 @@ xgb.cv <- function(params = list(), data, nrounds, nfold, label = NULL, missing
223223
for (f in cb$pre_iter) f()
224224

225225
msg <- lapply(bst_folds, function(fd) {
226-
xgb.iter.update(fd$bst, fd$dtrain, iteration - 1, obj)
227-
xgb.iter.eval(fd$bst, fd$watchlist, iteration - 1, feval)
226+
xgb.iter.update(
227+
booster_handle = fd$bst,
228+
dtrain = fd$dtrain,
229+
iter = iteration - 1,
230+
obj = obj
231+
)
232+
xgb.iter.eval(
233+
booster_handle = fd$bst,
234+
watchlist = fd$watchlist,
235+
iter = iteration - 1,
236+
feval = feval
237+
)
228238
})
229239
msg <- simplify2array(msg)
230240
bst_evaluation <- rowMeans(msg)

R-package/R/xgb.train.R

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,21 @@ xgb.train <- function(params = list(), data, nrounds, watchlist = list(),
390390

391391
for (f in cb$pre_iter) f()
392392

393-
xgb.iter.update(bst$handle, dtrain, iteration - 1, obj)
393+
xgb.iter.update(
394+
booster_handle = bst$handle,
395+
dtrain = dtrain,
396+
iter = iteration - 1,
397+
obj = obj
398+
)
394399

395-
if (length(watchlist) > 0)
396-
bst_evaluation <- xgb.iter.eval(bst$handle, watchlist, iteration - 1, feval) # nolint: object_usage_linter
400+
if (length(watchlist) > 0) {
401+
bst_evaluation <- xgb.iter.eval( # nolint: object_usage_linter
402+
booster_handle = bst$handle,
403+
watchlist = watchlist,
404+
iter = iteration - 1,
405+
feval = feval
406+
)
407+
}
397408

398409
xgb.attr(bst$handle, 'niter') <- iteration - 1
399410

0 commit comments

Comments
 (0)