Skip to content

Commit

Permalink
Merge pull request #216 from tidymodels/complement-rsplit
Browse files Browse the repository at this point in the history
New inheritance structure for `rsplit` objects and updated `complement()` methods
  • Loading branch information
topepo authored Feb 9, 2021
2 parents 54e3235 + d2755c5 commit 5874b1c
Show file tree
Hide file tree
Showing 14 changed files with 607 additions and 114 deletions.
11 changes: 2 additions & 9 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@ S3method(.get_fingerprint,rset)
S3method(as.data.frame,rsplit)
S3method(as.integer,rsplit)
S3method(complement,apparent_split)
S3method(complement,boot_split)
S3method(complement,group_vfold_split)
S3method(complement,loo_split)
S3method(complement,mc_split)
S3method(complement,perm_split)
S3method(complement,default)
S3method(complement,rof_split)
S3method(complement,rsplit)
S3method(complement,sliding_index_split)
S3method(complement,sliding_period_split)
S3method(complement,sliding_window_split)
S3method(complement,val_split)
S3method(complement,vfold_split)
S3method(dim,rsplit)
S3method(gather,rset)
S3method(labels,rset)
Expand Down Expand Up @@ -215,7 +210,6 @@ export(bootstraps)
export(caret2rsample)
export(complement)
export(contains)
export(default_complement)
export(ends_with)
export(everything)
export(form_pred)
Expand Down Expand Up @@ -257,7 +251,6 @@ export(reg_intervals)
export(rolling_origin)
export(rsample2caret)
export(rset_reconstruct)
export(rsplit_complement)
export(sliding_index)
export(sliding_period)
export(sliding_window)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

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

* Changed the inheritance structure for `rsplit` objects from specific to general and simplified the methods for the `complement()` generic.


# rsample 0.0.8

* New `manual_rset()` for constructing rset objects manually from custom rsplits (tidymodels/tune#273).
Expand Down
3 changes: 1 addition & 2 deletions R/apparent.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ apparent <- function(data, ...) {

split_objs <-
add_class(split_objs,
cls = c("apparent", "rset"),
at_end = FALSE)
cls = c("apparent", "rset"))

split_objs
}
Expand Down
43 changes: 15 additions & 28 deletions R/complement.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@
#'
#' Given an `rsplit` object, `complement()` will determine which
#' of the data rows are contained in the assessment set. To save space,
#' many of the `rset` objects will not contain indices for the
#' many of the `rsplit` objects will not contain indices for the
#' assessment split.
#'
#' `rsplit_complement()` handles the determination for sets for most resampling
#' methods. Unless the row indices for the assessment set are already
#' determined, this function selects all of the rows that are not in the
#' analysis set and returns those as the assessment set.
#'
#' @param x An `rsplit` object
#' @param ... Not currently used
#' @return A integer vector.
Expand All @@ -29,41 +24,30 @@ complement <- function(x, ...)

#' @export
#' @rdname complement
rsplit_complement <- function(x, ...) {
complement.rsplit <- function(x, ...) {
if (!is_missing_out_id(x)) {
return(x$out_id)
} else {
(1:nrow(x$data))[-unique(x$in_id)]
}
}

#' @export
complement.vfold_split <- rsplit_complement
#' @export
complement.mc_split <- rsplit_complement
#' @export
complement.val_split <- rsplit_complement
#' @export
complement.loo_split <- rsplit_complement
#' @export
complement.group_vfold_split <- rsplit_complement
#' @export
complement.boot_split <- rsplit_complement
#' @export
complement.perm_split <- rsplit_complement
#' @export
#' @rdname complement
complement.rof_split <- function(x, ...) {
get_stored_out_id(x)
}
#' @export
#' @rdname complement
complement.sliding_window_split <- function(x, ...) {
get_stored_out_id(x)
}
#' @export
#' @rdname complement
complement.sliding_index_split <- function(x, ...) {
get_stored_out_id(x)
}
#' @export
#' @rdname complement
complement.sliding_period_split <- function(x, ...) {
get_stored_out_id(x)
}
Expand All @@ -83,6 +67,7 @@ get_stored_out_id <- function(x) {
}

#' @export
#' @rdname complement
complement.apparent_split <- function(x, ...) {
if (!is_missing_out_id(x)) {
return(x$out_id)
Expand All @@ -91,13 +76,15 @@ complement.apparent_split <- function(x, ...) {
}
}

#' Get the indices of the analysis set from the assessment set
#' @param ind A vector of integers for which rows of data belong in the
#' assessment set.
#' @param n A single integer for the total number of rows in the data set.
#' @return A named list of integer vectors.
#' @export
#' @keywords internal
complement.default <- function(x, ...) {
cls <- paste0("'", class(x), "'", collapse = ", ")
rlang::abort(
paste("No `complement()` method for this class(es)", cls)
)
}

# Get the indices of the analysis set from the assessment set
default_complement <- function(ind, n) {
list(analysis = setdiff(1:n, ind),
assessment = unique(ind))
Expand Down
4 changes: 2 additions & 2 deletions R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ names0 <- function(num, prefix = "x") {
paste0(prefix, ind)
}

add_class <- function(x, cls, at_end = TRUE) {
add_class <- function(x, cls, at_end = FALSE) {
class(x) <- if (at_end)
c(class(x), cls)
else
Expand Down Expand Up @@ -89,7 +89,7 @@ split_unnamed <- function(x, f) {
#' @export
#' @rdname get_fingerprint
.get_fingerprint.default <- function(x, ...) {
cls <- paste("'", class(x), "'", sep = ", ")
cls <- paste0("'", class(x), "'", collapse = ", ")
rlang::abort(
paste("No `.get_fingerprint()` method for this class(es)", cls)
)
Expand Down
2 changes: 1 addition & 1 deletion R/nest.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ nested_cv <- function(data, outside, inside) {

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

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

attr(out, "outside") <- cl$outside
attr(out, "inside") <- cl$inside
Expand Down
2 changes: 1 addition & 1 deletion R/rset.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ new_rset <- function(splits, ids, attrib = NULL,
}

if (length(subclass) > 0) {
res <- add_class(res, cls = subclass, at_end = FALSE)
res <- add_class(res, cls = subclass)
}

fingerprint <- rlang::hash(res)
Expand Down
26 changes: 18 additions & 8 deletions man/complement.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 0 additions & 21 deletions man/default_complement.Rd

This file was deleted.

101 changes: 62 additions & 39 deletions revdep/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,71 @@

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

# Dependencies

|package |old |new |Δ |
|:----------|:-------|:-------|:--|
|rsample |0.0.6 |0.0.7 |* |
|assertthat |0.2.1 |0.2.1 | |
|cli |2.0.2 |2.0.2 | |
|crayon |1.3.4 |1.3.4 | |
|digest |0.6.25 |0.6.25 | |
|dplyr |1.0.0 |1.0.0 | |
|ellipsis |0.3.1 |0.3.1 | |
|fansi |0.4.1 |0.4.1 | |
|furrr |0.1.0 |0.1.0 | |
|future |1.17.0 |1.17.0 | |
|generics |0.0.2 |0.0.2 | |
|globals |0.12.5 |0.12.5 | |
|glue |1.4.1 |1.4.1 | |
|lifecycle |0.2.0 |0.2.0 | |
|listenv |0.8.0 |0.8.0 | |
|magrittr |1.5 |1.5 | |
|pillar |1.4.4 |1.4.4 | |
|pkgconfig |2.0.3 |2.0.3 | |
|purrr |0.3.4 |0.3.4 | |
|R6 |2.4.1 |2.4.1 | |
|Rcpp |1.0.4.6 |1.0.4.6 | |
|rlang |0.4.6 |0.4.6 | |
|stringi |1.4.6 |1.4.6 | |
|tibble |3.0.1 |3.0.1 | |
|tidyr |1.1.0 |1.1.0 | |
|tidyselect |1.1.0 |1.1.0 | |
|utf8 |1.1.4 |1.1.4 | |
|vctrs |0.3.0 |0.3.0 | |
|package |old |new |Δ |
|:----------|:------|:----------|:--|
|rsample |0.0.8 |0.0.8.9001 |* |
|assertthat |0.2.1 |0.2.1 | |
|cli |2.3.0 |2.3.0 | |
|cpp11 |0.2.6 |0.2.6 | |
|crayon |1.4.0 |1.4.0 | |
|digest |0.6.27 |0.6.27 | |
|dplyr |1.0.4 |1.0.4 | |
|ellipsis |0.3.1 |0.3.1 | |
|fansi |0.4.2 |0.4.2 | |
|furrr |0.2.2 |0.2.2 | |
|future |1.21.0 |1.21.0 | |
|generics |0.1.0 |0.1.0 | |
|globals |0.14.0 |0.14.0 | |
|glue |1.4.2 |1.4.2 | |
|lifecycle |0.2.0 |0.2.0 | |
|listenv |0.8.0 |0.8.0 | |
|magrittr |2.0.1 |2.0.1 | |
|modeldata |0.1.0 |NA |* |
|parallelly |1.23.0 |1.23.0 | |
|pillar |1.4.7 |1.4.7 | |
|pkgconfig |2.0.3 |2.0.3 | |
|purrr |0.3.4 |0.3.4 | |
|R6 |2.5.0 |2.5.0 | |
|rlang |0.4.10 |0.4.10 | |
|slider |0.1.5 |0.1.5 | |
|tibble |3.0.6 |3.0.6 | |
|tidyr |1.1.2 |1.1.2 | |
|tidyselect |1.1.0 |1.1.0 | |
|utf8 |1.1.4 |1.1.4 | |
|vctrs |0.3.6 |0.3.6 | |
|warp |0.2.0 |0.2.0 | |

# Revdeps

## Failed to check (15)

|package |version |error |warning |note |
|:-------------|:-------|:-----|:-------|:----|
|baguette |? | | | |
|broom |? | | | |
|butcher |? | | | |
|embed |? | | | |
|MachineShop |? | | | |
|probably |? | | | |
|psfmi |? | | | |
|recipes |? | | | |
|solitude |? | | | |
|tfdatasets |? | | | |
|tidymodels |? | | | |
|tidyposterior |? | | | |
|tidyrules |? | | | |
|timetk |? | | | |
|tune |? | | | |

Binary file modified revdep/data.sqlite
Binary file not shown.
Loading

0 comments on commit 5874b1c

Please sign in to comment.