Skip to content

Commit 5874b1c

Browse files
authored
Merge pull request #216 from tidymodels/complement-rsplit
New inheritance structure for `rsplit` objects and updated `complement()` methods
2 parents 54e3235 + d2755c5 commit 5874b1c

14 files changed

+607
-114
lines changed

NAMESPACE

+2-9
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@ S3method(.get_fingerprint,rset)
77
S3method(as.data.frame,rsplit)
88
S3method(as.integer,rsplit)
99
S3method(complement,apparent_split)
10-
S3method(complement,boot_split)
11-
S3method(complement,group_vfold_split)
12-
S3method(complement,loo_split)
13-
S3method(complement,mc_split)
14-
S3method(complement,perm_split)
10+
S3method(complement,default)
1511
S3method(complement,rof_split)
12+
S3method(complement,rsplit)
1613
S3method(complement,sliding_index_split)
1714
S3method(complement,sliding_period_split)
1815
S3method(complement,sliding_window_split)
19-
S3method(complement,val_split)
20-
S3method(complement,vfold_split)
2116
S3method(dim,rsplit)
2217
S3method(gather,rset)
2318
S3method(labels,rset)
@@ -215,7 +210,6 @@ export(bootstraps)
215210
export(caret2rsample)
216211
export(complement)
217212
export(contains)
218-
export(default_complement)
219213
export(ends_with)
220214
export(everything)
221215
export(form_pred)
@@ -257,7 +251,6 @@ export(reg_intervals)
257251
export(rolling_origin)
258252
export(rsample2caret)
259253
export(rset_reconstruct)
260-
export(rsplit_complement)
261254
export(sliding_index)
262255
export(sliding_period)
263256
export(sliding_window)

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
* The `obj_sum()` method for `rsplit` objects was updated.
1616

17+
* Changed the inheritance structure for `rsplit` objects from specific to general and simplified the methods for the `complement()` generic.
18+
19+
1720
# rsample 0.0.8
1821

1922
* New `manual_rset()` for constructing rset objects manually from custom rsplits (tidymodels/tune#273).

R/apparent.R

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ apparent <- function(data, ...) {
2424

2525
split_objs <-
2626
add_class(split_objs,
27-
cls = c("apparent", "rset"),
28-
at_end = FALSE)
27+
cls = c("apparent", "rset"))
2928

3029
split_objs
3130
}

R/complement.R

+15-28
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@
55
#'
66
#' Given an `rsplit` object, `complement()` will determine which
77
#' of the data rows are contained in the assessment set. To save space,
8-
#' many of the `rset` objects will not contain indices for the
8+
#' many of the `rsplit` objects will not contain indices for the
99
#' assessment split.
1010
#'
11-
#' `rsplit_complement()` handles the determination for sets for most resampling
12-
#' methods. Unless the row indices for the assessment set are already
13-
#' determined, this function selects all of the rows that are not in the
14-
#' analysis set and returns those as the assessment set.
15-
#'
1611
#' @param x An `rsplit` object
1712
#' @param ... Not currently used
1813
#' @return A integer vector.
@@ -29,41 +24,30 @@ complement <- function(x, ...)
2924

3025
#' @export
3126
#' @rdname complement
32-
rsplit_complement <- function(x, ...) {
27+
complement.rsplit <- function(x, ...) {
3328
if (!is_missing_out_id(x)) {
3429
return(x$out_id)
3530
} else {
3631
(1:nrow(x$data))[-unique(x$in_id)]
3732
}
3833
}
39-
40-
#' @export
41-
complement.vfold_split <- rsplit_complement
42-
#' @export
43-
complement.mc_split <- rsplit_complement
44-
#' @export
45-
complement.val_split <- rsplit_complement
46-
#' @export
47-
complement.loo_split <- rsplit_complement
48-
#' @export
49-
complement.group_vfold_split <- rsplit_complement
50-
#' @export
51-
complement.boot_split <- rsplit_complement
52-
#' @export
53-
complement.perm_split <- rsplit_complement
5434
#' @export
35+
#' @rdname complement
5536
complement.rof_split <- function(x, ...) {
5637
get_stored_out_id(x)
5738
}
5839
#' @export
40+
#' @rdname complement
5941
complement.sliding_window_split <- function(x, ...) {
6042
get_stored_out_id(x)
6143
}
6244
#' @export
45+
#' @rdname complement
6346
complement.sliding_index_split <- function(x, ...) {
6447
get_stored_out_id(x)
6548
}
6649
#' @export
50+
#' @rdname complement
6751
complement.sliding_period_split <- function(x, ...) {
6852
get_stored_out_id(x)
6953
}
@@ -83,6 +67,7 @@ get_stored_out_id <- function(x) {
8367
}
8468

8569
#' @export
70+
#' @rdname complement
8671
complement.apparent_split <- function(x, ...) {
8772
if (!is_missing_out_id(x)) {
8873
return(x$out_id)
@@ -91,13 +76,15 @@ complement.apparent_split <- function(x, ...) {
9176
}
9277
}
9378

94-
#' Get the indices of the analysis set from the assessment set
95-
#' @param ind A vector of integers for which rows of data belong in the
96-
#' assessment set.
97-
#' @param n A single integer for the total number of rows in the data set.
98-
#' @return A named list of integer vectors.
9979
#' @export
100-
#' @keywords internal
80+
complement.default <- function(x, ...) {
81+
cls <- paste0("'", class(x), "'", collapse = ", ")
82+
rlang::abort(
83+
paste("No `complement()` method for this class(es)", cls)
84+
)
85+
}
86+
87+
# Get the indices of the analysis set from the assessment set
10188
default_complement <- function(ind, n) {
10289
list(analysis = setdiff(1:n, ind),
10390
assessment = unique(ind))

R/misc.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ names0 <- function(num, prefix = "x") {
3333
paste0(prefix, ind)
3434
}
3535

36-
add_class <- function(x, cls, at_end = TRUE) {
36+
add_class <- function(x, cls, at_end = FALSE) {
3737
class(x) <- if (at_end)
3838
c(class(x), cls)
3939
else
@@ -89,7 +89,7 @@ split_unnamed <- function(x, f) {
8989
#' @export
9090
#' @rdname get_fingerprint
9191
.get_fingerprint.default <- function(x, ...) {
92-
cls <- paste("'", class(x), "'", sep = ", ")
92+
cls <- paste0("'", class(x), "'", collapse = ", ")
9393
rlang::abort(
9494
paste("No `.get_fingerprint()` method for this class(es)", cls)
9595
)

R/nest.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ nested_cv <- function(data, outside, inside) {
7979

8080
out <- dplyr::mutate(outside, inner_resamples = inside)
8181

82-
out <- add_class(out, cls = "nested_cv", at_end = FALSE)
82+
out <- add_class(out, cls = "nested_cv")
8383

8484
attr(out, "outside") <- cl$outside
8585
attr(out, "inside") <- cl$inside

R/rset.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ new_rset <- function(splits, ids, attrib = NULL,
7171
}
7272

7373
if (length(subclass) > 0) {
74-
res <- add_class(res, cls = subclass, at_end = FALSE)
74+
res <- add_class(res, cls = subclass)
7575
}
7676

7777
fingerprint <- rlang::hash(res)

man/complement.Rd

+18-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/default_complement.Rd

-21
This file was deleted.

revdep/README.md

+62-39
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,71 @@
22

33
|field |value |
44
|:--------|:----------------------------|
5-
|version |R version 4.0.0 (2020-04-24) |
6-
|os |macOS Mojave 10.14.6 |
7-
|system |x86_64, darwin17.0 |
8-
|ui |RStudio |
9-
|language |(EN) |
10-
|collate |en_US.UTF-8 |
11-
|ctype |en_US.UTF-8 |
12-
|tz |America/New_York |
13-
|date |2020-06-03 |
5+
|version |R version 4.0.3 (2020-10-10) |
6+
|os |Ubuntu 18.04.5 LTS |
7+
|system |x86_64, linux-gnu |
8+
|ui |X11 |
9+
|language |en |
10+
|collate |en_GB.UTF-8 |
11+
|ctype |en_GB.UTF-8 |
12+
|tz |Europe/London |
13+
|date |2021-02-03 |
1414

1515
# Dependencies
1616

17-
|package |old |new |Δ |
18-
|:----------|:-------|:-------|:--|
19-
|rsample |0.0.6 |0.0.7 |* |
20-
|assertthat |0.2.1 |0.2.1 | |
21-
|cli |2.0.2 |2.0.2 | |
22-
|crayon |1.3.4 |1.3.4 | |
23-
|digest |0.6.25 |0.6.25 | |
24-
|dplyr |1.0.0 |1.0.0 | |
25-
|ellipsis |0.3.1 |0.3.1 | |
26-
|fansi |0.4.1 |0.4.1 | |
27-
|furrr |0.1.0 |0.1.0 | |
28-
|future |1.17.0 |1.17.0 | |
29-
|generics |0.0.2 |0.0.2 | |
30-
|globals |0.12.5 |0.12.5 | |
31-
|glue |1.4.1 |1.4.1 | |
32-
|lifecycle |0.2.0 |0.2.0 | |
33-
|listenv |0.8.0 |0.8.0 | |
34-
|magrittr |1.5 |1.5 | |
35-
|pillar |1.4.4 |1.4.4 | |
36-
|pkgconfig |2.0.3 |2.0.3 | |
37-
|purrr |0.3.4 |0.3.4 | |
38-
|R6 |2.4.1 |2.4.1 | |
39-
|Rcpp |1.0.4.6 |1.0.4.6 | |
40-
|rlang |0.4.6 |0.4.6 | |
41-
|stringi |1.4.6 |1.4.6 | |
42-
|tibble |3.0.1 |3.0.1 | |
43-
|tidyr |1.1.0 |1.1.0 | |
44-
|tidyselect |1.1.0 |1.1.0 | |
45-
|utf8 |1.1.4 |1.1.4 | |
46-
|vctrs |0.3.0 |0.3.0 | |
17+
|package |old |new |Δ |
18+
|:----------|:------|:----------|:--|
19+
|rsample |0.0.8 |0.0.8.9001 |* |
20+
|assertthat |0.2.1 |0.2.1 | |
21+
|cli |2.3.0 |2.3.0 | |
22+
|cpp11 |0.2.6 |0.2.6 | |
23+
|crayon |1.4.0 |1.4.0 | |
24+
|digest |0.6.27 |0.6.27 | |
25+
|dplyr |1.0.4 |1.0.4 | |
26+
|ellipsis |0.3.1 |0.3.1 | |
27+
|fansi |0.4.2 |0.4.2 | |
28+
|furrr |0.2.2 |0.2.2 | |
29+
|future |1.21.0 |1.21.0 | |
30+
|generics |0.1.0 |0.1.0 | |
31+
|globals |0.14.0 |0.14.0 | |
32+
|glue |1.4.2 |1.4.2 | |
33+
|lifecycle |0.2.0 |0.2.0 | |
34+
|listenv |0.8.0 |0.8.0 | |
35+
|magrittr |2.0.1 |2.0.1 | |
36+
|modeldata |0.1.0 |NA |* |
37+
|parallelly |1.23.0 |1.23.0 | |
38+
|pillar |1.4.7 |1.4.7 | |
39+
|pkgconfig |2.0.3 |2.0.3 | |
40+
|purrr |0.3.4 |0.3.4 | |
41+
|R6 |2.5.0 |2.5.0 | |
42+
|rlang |0.4.10 |0.4.10 | |
43+
|slider |0.1.5 |0.1.5 | |
44+
|tibble |3.0.6 |3.0.6 | |
45+
|tidyr |1.1.2 |1.1.2 | |
46+
|tidyselect |1.1.0 |1.1.0 | |
47+
|utf8 |1.1.4 |1.1.4 | |
48+
|vctrs |0.3.6 |0.3.6 | |
49+
|warp |0.2.0 |0.2.0 | |
4750

4851
# Revdeps
4952

53+
## Failed to check (15)
54+
55+
|package |version |error |warning |note |
56+
|:-------------|:-------|:-----|:-------|:----|
57+
|baguette |? | | | |
58+
|broom |? | | | |
59+
|butcher |? | | | |
60+
|embed |? | | | |
61+
|MachineShop |? | | | |
62+
|probably |? | | | |
63+
|psfmi |? | | | |
64+
|recipes |? | | | |
65+
|solitude |? | | | |
66+
|tfdatasets |? | | | |
67+
|tidymodels |? | | | |
68+
|tidyposterior |? | | | |
69+
|tidyrules |? | | | |
70+
|timetk |? | | | |
71+
|tune |? | | | |
72+

revdep/data.sqlite

24 KB
Binary file not shown.

0 commit comments

Comments
 (0)