@@ -0,0 +1,46 @@
Loading
1 +
#' Manual resampling
2 +
#'
3 +
#' `manual_rset()` is used for constructing the most minimal rset possible. It
4 +
#' can be useful when you have custom rsplit objects built from
5 +
#' [make_splits()], or when you want to create a new rset from splits
6 +
#' contained within an existing rset.
7 +
#'
8 +
#' @param splits A list of `"rsplit"` objects. It is easiest to create these
9 +
#'   using [make_splits()].
10 +
#'
11 +
#' @param ids A character vector of ids. The length of `ids` must be the same
12 +
#'   as the length of `splits`.
13 +
#'
14 +
#' @export
15 +
#' @examples
16 +
#' df <- data.frame(x = c(1, 2, 3, 4, 5, 6))
17 +
#'
18 +
#' # Create an rset from custom indices
19 +
#' indices <- list(
20 +
#'   list(analysis = c(1L, 2L), assessment = 3L),
21 +
#'   list(analysis = c(4L, 5L), assessment = 6L)
22 +
#' )
23 +
#'
24 +
#' splits <- lapply(indices, make_splits, data = df)
25 +
#'
26 +
#' manual_rset(splits, c("Split 1", "Split 2"))
27 +
#'
28 +
#' # You can also use this to create an rset from a subset of an
29 +
#' # existing rset
30 +
#' resamples <- vfold_cv(mtcars)
31 +
#' best_split <- resamples[5,]
32 +
#' manual_rset(best_split$splits, best_split$id)
33 +
manual_rset <- function(splits, ids) {
34 +
  new_manual_rset(splits, ids)
35 +
}
36 +
37 +
new_manual_rset <- function(splits, ids) {
38 +
  new_rset(splits, ids, subclass = c("manual_rset", "rset"))
39 +
}
40 +
41 +
#' @export
42 +
print.manual_rset <- function(x, ...) {
43 +
  cat("#", pretty(x), "\n")
44 +
  class(x) <- class(x)[!(class(x) %in% c("manual_rset", "rset"))]
45 +
  print(x, ...)
46 +
}

@@ -157,3 +157,7 @@
Loading
157 157
    TRUE ~ paste0(round(x/1000000, digits = digits), "M"),
158 158
  )
159 159
}
160 +
161 +
is_rsplit <- function(x) {
162 +
  inherits(x, "rsplit")
163 +
}

@@ -214,6 +214,14 @@
Loading
214 214
  paste0("Group ", details$v, "-fold cross-validation")
215 215
}
216 216
217 +
#' @export pretty.manual_rset
218 +
#' @export
219 +
#' @method pretty manual_rset
220 +
#' @rdname pretty.vfold_cv
221 +
pretty.manual_rset <- function(x, ...) {
222 +
  "Manual resampling"
223 +
}
224 +
217 225
218 226
#' Augment a data set with resampling identifiers
219 227
#'

@@ -636,6 +636,58 @@
Loading
636 636
  df_cast(x, to, ..., x_arg = x_arg, to_arg = to_arg)
637 637
}
638 638
639 +
# ------------------------------------------------------------------------------
640 +
# manual_rset
641 +
642 +
#' @export
643 +
vec_restore.manual_rset <- function(x, to, ...) {
644 +
  rset_reconstruct(x, to)
645 +
}
646 +
647 +
648 +
#' @export
649 +
vec_ptype2.manual_rset.manual_rset <- function(x, y, ..., x_arg = "", y_arg = "") {
650 +
  stop_never_called("vec_ptype2.manual_rset.manual_rset")
651 +
}
652 +
#' @export
653 +
vec_ptype2.manual_rset.tbl_df <- function(x, y, ..., x_arg = "", y_arg = "") {
654 +
  stop_never_called("vec_ptype2.manual_rset.tbl_df")
655 +
}
656 +
#' @export
657 +
vec_ptype2.tbl_df.manual_rset <- function(x, y, ..., x_arg = "", y_arg = "") {
658 +
  stop_never_called("vec_ptype2.tbl_df.manual_rset")
659 +
}
660 +
#' @export
661 +
vec_ptype2.manual_rset.data.frame <- function(x, y, ..., x_arg = "", y_arg = "") {
662 +
  stop_never_called("vec_ptype2.manual_rset.data.frame")
663 +
}
664 +
#' @export
665 +
vec_ptype2.data.frame.manual_rset <- function(x, y, ..., x_arg = "", y_arg = "") {
666 +
  stop_never_called("vec_ptype2.data.frame.manual_rset")
667 +
}
668 +
669 +
670 +
#' @export
671 +
vec_cast.manual_rset.manual_rset <- function(x, to, ..., x_arg = "", to_arg = "") {
672 +
  stop_incompatible_cast_rset(x, to, x_arg = x_arg, to_arg = to_arg)
673 +
}
674 +
#' @export
675 +
vec_cast.manual_rset.tbl_df <- function(x, to, ..., x_arg = "", to_arg = "") {
676 +
  stop_incompatible_cast_rset(x, to, x_arg = x_arg, to_arg = to_arg)
677 +
}
678 +
#' @export
679 +
vec_cast.tbl_df.manual_rset <- function(x, to, ..., x_arg = "", to_arg = "") {
680 +
  tib_cast(x, to, ..., x_arg = x_arg, to_arg = to_arg)
681 +
}
682 +
#' @export
683 +
vec_cast.manual_rset.data.frame <- function(x, to, ..., x_arg = "", to_arg = "") {
684 +
  stop_incompatible_cast_rset(x, to, x_arg = x_arg, to_arg = to_arg)
685 +
}
686 +
#' @export
687 +
vec_cast.data.frame.manual_rset <- function(x, to, ..., x_arg = "", to_arg = "") {
688 +
  df_cast(x, to, ..., x_arg = x_arg, to_arg = to_arg)
689 +
}
690 +
639 691
# ------------------------------------------------------------------------------
640 692
# apparent
641 693

@@ -79,6 +79,7 @@
Loading
79 79
  sliding_window   = c("lookback", "assess_start", "assess_stop", "complete", "step", "skip"),
80 80
  sliding_index    = c("lookback", "assess_start", "assess_stop", "complete", "step", "skip"),
81 81
  sliding_period   = c("period", "lookback", "assess_start", "assess_stop", "complete", "step", "skip", "every", "origin"),
82 +
  manual_rset      = character(),
82 83
  apparent         = character(),
83 84
  tbl_df           = character()
84 85
)
@@ -130,6 +131,7 @@
Loading
130 131
    sliding_window   = sliding_window(test_data()),
131 132
    sliding_index    = sliding_index(test_data(), index),
132 133
    sliding_period   = sliding_period(test_data(), index, "week"),
134 +
    manual_rset      = manual_rset(bootstraps(test_data())$splits[1:2], c("ID1", "ID2")),
133 135
    apparent         = apparent(test_data())
134 136
  )
135 137
})

@@ -35,6 +35,12 @@
Loading
35 35
    }
36 36
  }
37 37
38 +
  where_rsplits <- vapply(splits[["splits"]], is_rsplit, logical(1))
39 +
40 +
  if (!all(where_rsplits)) {
41 +
    rlang::abort("Each element of `splits` must be an `rsplit` object.")
42 +
  }
43 +
38 44
  if (nrow(ids) != nrow(splits)) {
39 45
    rlang::abort("Split and ID vectors have different lengths.")
40 46
  }
Files Coverage
R 81.61%
Project Totals (27 files) 81.61%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
        informational: true
10
    patch:
11
      default:
12
        target: auto
13
        threshold: 1%
14
        informational: true
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading