Skip to content

Extract the 3× duplicated prediction-collation lambda in adaptive.R #1430

Open

Description

@topepo

The same ~6-line anonymous function (coerce char→factor, build pred/obs frame, optionally attach weights) is passed to lapply() three times, verbatim:

predicted <- lapply(predicted,
                    function(x, y, wts, lv) {
                      if(!is.factor(x) & is.character(x)) x <- factor(as.character(x), levels = lv)
                      out <- data.frame(pred = x, obs = y, stringsAsFactors = FALSE)
                      if(!is.null(wts)) out$weights <- wts
                      out
                    }, ...)

Extract a named internal helper (e.g. collate_submodel_pred()) and call it from all three sites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions