tidymodels / tidymodels/rsample

Printing with resampling weights

Open
#593 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
R
Stars
343
Forks
67
Avg merge
1h 9m
Merged PRs (30d)
2

Description

With printing in the rset objects, I think that we'll have to move this code into an rsample PR.

Most of the rsets have a superseding class (like v_fold) and the print method for that class happens first.

Using v_fold as an example, its print method removes the first two classes (v_fold and rset) so that the remaining printing is the default tibble printing. That's why there is not a rsample:::print.rset method.

I'm going to temporarily remove the print methods and make this comment an issue for rsample, and then Hannah can take a look (who is out of office next week 😿)


#' @export
print.rset <- function(x, ...) {
  fold_weights <- attr(x, ".fold_weights")

  if (!is.null(fold_weights)) {
    # Create a tibble with fold weights as a column
    x_tbl <- tibble::as_tibble(x)
    x_tbl$fold_weight <- fold_weights
    print(x_tbl, ...)
  } else {
    # Use default behavior
    NextMethod("print")
  }
}

#' @export
print.manual_rset <- function(x, ...) {
  fold_weights <- attr(x, ".fold_weights")

  if (!is.null(fold_weights)) {
    # Create a tibble with fold weights as a column
    x_tbl <- tibble::as_tibble(x)
    x_tbl$fold_weight <- fold_weights
    print(x_tbl, ...)
  } else {
    # Use default behavior for manual_rset
    NextMethod("print")
  }
}

Originally posted by @topepo in https://github.com/tidymodels/tune/issues/1007#issuecomment-3417377573

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the S3 print methods for rset and manual_rset and inspect how subclasses such as v_fold dispatch printing. Check the proposed weighted-output behavior against the existing default printing path, then verify that weighted rsets show fold_weight while unweighted objects retain their current output.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
developer-experience
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.