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 1
  new_manual_rset(splits, ids)
35
}
36

37
new_manual_rset <- function(splits, ids) {
38 1
  new_rset(splits, ids, subclass = c("manual_rset", "rset"))
39
}
40

41
#' @export
42
print.manual_rset <- function(x, ...) {
43 0
  cat("#", pretty(x), "\n")
44 0
  class(x) <- class(x)[!(class(x) %in% c("manual_rset", "rset"))]
45 0
  print(x, ...)
46
}

Read our documentation on viewing source code .

Loading