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] Deprecation warning for non-function objective as argument #11204

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading