Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions R/initial_validation_split.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ initial_validation_split <- function(
)

# include those so that they can be attached to the `rset` later in `validation_set()`
if (!is.null(strata)) names(strata) <- NULL
if (!is.null(strata)) {
names(strata) <- NULL
}
val_att <- list(
prop = prop,
strata = strata,
Expand Down Expand Up @@ -264,7 +266,9 @@ group_initial_validation_split <- function(
)

# include those so that they can be attached to the `rset` later in `validation_set()`
if (!is.null(strata)) names(strata) <- NULL
if (!is.null(strata)) {
names(strata) <- NULL
}
val_att <- list(
group = group,
prop = prop,
Expand Down
4 changes: 3 additions & 1 deletion R/make_groups.R
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ balance_prop_helper <- function(prop, data_ind, v, replace) {
# if we somehow got the smallest group every time.
# If sampling without replacement, just reshuffle all the groups.
n <- nrow(freq_table)
if (replace) n <- n * prop * sum(freq_table$count) / min(freq_table$count)
if (replace) {
n <- n * prop * sum(freq_table$count) / min(freq_table$count)
}
n <- ceiling(n)

purrr::map(
Expand Down
8 changes: 6 additions & 2 deletions R/mc.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ mc_cv <- function(

split_objs$splits <- map(split_objs$splits, rm_out)

if (!is.null(strata)) names(strata) <- NULL
if (!is.null(strata)) {
names(strata) <- NULL
}
mc_att <- list(
prop = prop,
times = times,
Expand Down Expand Up @@ -206,7 +208,9 @@ group_mc_cv <- function(
)

# This is needed for printing checks; strata can't be missing for mc_cv
if (is.null(strata)) strata <- FALSE
if (is.null(strata)) {
strata <- FALSE
}

## We remove the holdout indices since it will save space and we can
## derive them later when they are needed.
Expand Down
4 changes: 3 additions & 1 deletion R/tidy.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
#' @export
tidy.rsplit <- function(x, unique_ind = TRUE, ...) {
check_dots_empty()
if (unique_ind) x$in_id <- unique(x$in_id)
if (unique_ind) {
x$in_id <- unique(x$in_id)
}
out <- tibble(
Row = c(x$in_id, complement(x)),
Data = rep(
Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test-reshuffle_rset.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ test_that("reshuffle_rset is working", {
# Select any non-grouped function in rset_subclasses with a strata argument:
supports_strata <- purrr::map_lgl(
names(supported_subclasses),
\(.x)
\(.x) {
any(names(formals(.x)) == "strata") && !any(names(formals(.x)) == "group")
}
)
supports_strata <- names(supported_subclasses)[supports_strata]

Expand All @@ -57,8 +58,9 @@ test_that("reshuffle_rset is working", {
# Select any grouped function in rset_subclasses with a strata argument:
grouped_strata <- purrr::map_lgl(
names(supported_subclasses),
\(.x)
\(.x) {
any(names(formals(.x)) == "strata") && any(names(formals(.x)) == "group")
}
)
grouped_strata <- names(supported_subclasses)[grouped_strata]

Expand Down
18 changes: 12 additions & 6 deletions tests/testthat/test-rolling_origin.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ test_that("larger holdout", {
)
expect_equal(
rs2$splits[[i]]$out_id,
(i + attr(rs2, "initial")): # fmt: skip
(i + attr(rs2, "initial") + attr(rs2, "assess") - 1) # fmt: skip
# fmt: skip
(i + attr(rs2, "initial")):
(i + attr(rs2, "initial") + attr(rs2, "assess") - 1)
# fmt: skip
)
}
})
Expand Down Expand Up @@ -72,8 +74,10 @@ test_that("skipping", {
for (i in 1:nrow(rs4)) {
expect_equal(
rs4$splits[[i]]$in_id,
(i + attr(rs4, "skip") * (i - 1)): # fmt: skip
(i + attr(rs4, "skip") * (i - 1) + attr(rs4, "initial") - 1) # fmt: skip
# fmt: skip
(i + attr(rs4, "skip") * (i - 1)):
(i + attr(rs4, "skip") * (i - 1) + attr(rs4, "initial") - 1)
# fmt: skip
)
expect_equal(
rs4$splits[[i]]$out_id,
Expand Down Expand Up @@ -103,8 +107,10 @@ test_that("lag", {
)
expect_equal(
rs5$splits[[i]]$out_id,
(i + attr(rs5, "initial") - attr(rs5, "lag")): # fmt: skip
(i + attr(rs5, "initial") + attr(rs5, "assess") - 1) # fmt: skip
# fmt: skip
(i + attr(rs5, "initial") - attr(rs5, "lag")):
(i + attr(rs5, "initial") + attr(rs5, "assess") - 1)
# fmt: skip
)
}

Expand Down