Skip to content

Commit 7103baf

Browse files
authored
[R] turn string objective argument into warning (dmlc#11204)
1 parent a46585a commit 7103baf

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

R-package/R/utils.R

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,24 @@ check.custom.obj <- function(params, objective) {
139139
if (!is.null(params[['objective']]) && !is.null(objective))
140140
stop("Setting objectives in 'params' and 'objective' at the same time is not allowed")
141141

142-
if (!is.null(objective) && typeof(objective) != 'closure')
142+
if (!is.null(objective) && typeof(objective) != 'closure') {
143+
if (is.character(objective)) {
144+
msg <- paste(
145+
"Argument 'objective' is only for custom objectives.",
146+
"For built-in objectives, pass the objective under 'params'.",
147+
sep = " "
148+
)
149+
error_on_deprecated <- getOption("xgboost.strict_mode", default = FALSE)
150+
if (error_on_deprecated) {
151+
stop(msg)
152+
} else {
153+
warning(msg, " This warning will become an error in a future version.")
154+
}
155+
params$objective <- objective
156+
return(list(params = params, objective = NULL))
157+
}
143158
stop("'objective' must be a function")
159+
}
144160

145161
# handle the case when custom objective function was provided through params
146162
if (!is.null(params[['objective']]) &&

0 commit comments

Comments
 (0)