Skip to content

Fixed silent ignore of legacy predict flags (#12211)#12218

Open
Sanidhyavijay24 wants to merge 2 commits into
dmlc:masterfrom
Sanidhyavijay24:fix-r-predict-issue
Open

Fixed silent ignore of legacy predict flags (#12211)#12218
Sanidhyavijay24 wants to merge 2 commits into
dmlc:masterfrom
Sanidhyavijay24:fix-r-predict-issue

Conversation

@Sanidhyavijay24
Copy link
Copy Markdown
Contributor

This PR addresses #12211.
It prevents predict.xgboost from silently ignoring legacy boolean flags (like predcontrib = TRUE). These flags are now mapped to the modern type argument with a deprecation warning. Additionally, any unknown arguments in ... will now trigger an error to prevent typos from causing silent failures.

predict.xgboost was silently ignoring boolean flags like predcontrib=TRUE since they were absorbed by '...'. This maps those legacy flags to the appropriate 'type' and issues a deprecation warning so we don't break backward compatibility. Any completely unknown arguments in '...' will now throw a proper error.
Copilot AI review requested due to automatic review settings May 19, 2026 09:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the R predict.xgboost S3 method to prevent silent ignoring of legacy boolean prediction flags (e.g., predcontrib = TRUE) by mapping them to the modern type argument with a deprecation warning, and to error on unsupported arguments passed via ... to avoid silent typos.

Changes:

  • Map legacy predict flags provided via ... (e.g., predcontrib) to type = "<...>" and emit a deprecation warning.
  • Error out when any unsupported arguments are provided in ....
  • Add test coverage for the new warning/error behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
R-package/R/xgboost.R Adds legacy-flag mapping logic for predict.xgboost(...) and rejects unknown ... args.
R-package/tests/testthat/test_xgboost.R Adds a regression test for legacy flag mapping + unknown ... argument errors.
Comments suppressed due to low confidence (3)

R-package/R/xgboost.R:1379

  • The legacy-argument mapping only inspects the first matched legacy flag (found_legacy[1]). This can fail to map a TRUE flag if an earlier legacy flag is present but FALSE (e.g., outputmargin = FALSE, predcontrib = TRUE), and it also silently ignores/overrides cases where multiple legacy flags are provided. Consider computing which legacy flags are isTRUE(), erroring on >1 TRUE (or conflicts with an explicit non-default 'type'), and then mapping the single TRUE flag deterministically.
    found_legacy <- intersect(names(dots), names(mapping))
    
    if (length(found_legacy) > 0) {
      legacy_arg <- found_legacy[1]
      if (isTRUE(dots[[legacy_arg]])) {
        type <- mapping[[legacy_arg]]
        warning(
          sprintf(
            "Argument '%s' is deprecated. Please use type = '%s' instead.",
            legacy_arg, type
          ),
          call. = FALSE
        )
      }
      dots <- dots[setdiff(names(dots), names(mapping))]
    }

R-package/R/xgboost.R:1363

  • approxcontrib is mapped to type = 'contrib' here, but predict.xgboost never passes approxcontrib through to predict.xgb.Booster, so approxcontrib=TRUE will be silently ignored (and will compute exact SHAP instead of the requested approximation). Either add support for approxcontrib in predict.xgboost (and pass it through), or remove this mapping and error/warn with guidance (e.g., use predict.xgb.Booster for approxcontrib).
    mapping <- list(
      outputmargin = "raw",
      predleaf = "leaf",
      predcontrib = "contrib",
      approxcontrib = "contrib",
      predinteraction = "interaction"
    )

R-package/R/xgboost.R:1385

  • If '...' contains unnamed arguments, names(dots) will include "" and the error message will render as an empty entry ("not supported ()."), which is hard to debug. Consider detecting unnamed elements and printing a placeholder like "" or including positional indices in the message.
    if (length(dots) > 0) {
      stop(
        "predict.xgboost: arguments in '...' are not supported (",
        paste(names(dots), collapse = ", "), ")."
      )

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread R-package/tests/testthat/test_xgboost.R
Comment thread R-package/R/xgboost.R
- Improved intent detection by checking for isTRUE() in legacy flags.
- Use dots[found_legacy] <- NULL for safer subsetting.
- Handle unnamed arguments in '...' with descriptive '<unnamed>' error messages.
- Update roxygen2 documentation and metadata.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants