Skip to content

Commit

Permalink
[R] turn string objective argument into warning (#11204)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cortes authored Feb 6, 2025
1 parent a46585a commit 7103baf
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion R-package/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,24 @@ check.custom.obj <- function(params, objective) {
if (!is.null(params[['objective']]) && !is.null(objective))
stop("Setting objectives in 'params' and 'objective' at the same time is not allowed")

if (!is.null(objective) && typeof(objective) != 'closure')
if (!is.null(objective) && typeof(objective) != 'closure') {
if (is.character(objective)) {
msg <- paste(
"Argument 'objective' is only for custom objectives.",
"For built-in objectives, pass the objective under 'params'.",
sep = " "
)
error_on_deprecated <- getOption("xgboost.strict_mode", default = FALSE)
if (error_on_deprecated) {
stop(msg)
} else {
warning(msg, " This warning will become an error in a future version.")
}
params$objective <- objective
return(list(params = params, objective = NULL))
}
stop("'objective' must be a function")
}

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

0 comments on commit 7103baf

Please sign in to comment.