Skip to content

Commit 14bb65d

Browse files
authored
Merge pull request #567 from tidymodels:upkeep-2025-04
Upkeep 2025-04
2 parents 4929050 + 0808389 commit 14bb65d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+305
-269
lines changed

DESCRIPTION

+8-10
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ Authors@R: c(
66
comment = c(ORCID = "0000-0002-6049-5258")),
77
person("Fanny", "Chow", , "[email protected]", role = "aut"),
88
person("Max", "Kuhn", , "[email protected]", role = "aut"),
9-
person("Michael", "Mahoney", , "[email protected]", role = c("aut"),
9+
person("Michael", "Mahoney", , "[email protected]", role = "aut",
1010
comment = c(ORCID = "0000-0003-2402-304X")),
11-
person("Julia", "Silge", , "[email protected]", role = c("aut"),
11+
person("Julia", "Silge", , "[email protected]", role = "aut",
1212
comment = c(ORCID = "0000-0002-3671-836X")),
1313
person("Hadley", "Wickham", , "[email protected]", role = "aut"),
14-
person("Posit Software, PBC", role = c("cph", "fnd"))
14+
person("Posit Software, PBC", role = c("cph", "fnd"),
15+
comment = c(ROR = "03wc8by49"))
1516
)
1617
Description: Classes and functions to create and summarize different types
1718
of resampling objects (e.g. bootstrap, cross-validation).
1819
License: MIT + file LICENSE
1920
URL: https://rsample.tidymodels.org, https://github.com/tidymodels/rsample
2021
BugReports: https://github.com/tidymodels/rsample/issues
2122
Depends:
22-
R (>= 3.6)
23+
R (>= 4.1)
2324
Imports:
2425
cli,
2526
dplyr (>= 1.1.1),
@@ -52,12 +53,9 @@ Suggests:
5253
xml2
5354
VignetteBuilder:
5455
knitr
55-
Config/Needs/website:
56-
GGally,
57-
nlstools,
58-
tidymodels,
59-
tidyverse/tidytemplate
56+
Config/Needs/website: GGally, nlstools, tidymodels, tidyverse/tidytemplate
57+
Config/testthat/edition: 3
58+
Config/usethis/last-upkeep: 2025-04-23
6059
Encoding: UTF-8
6160
Roxygen: list(markdown = TRUE)
6261
RoxygenNote: 7.3.2
63-
Config/testthat/edition: 3

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
YEAR: 2021
1+
YEAR: 2025
22
COPYRIGHT HOLDER: rsample authors

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MIT License
22

3-
Copyright (c) 2021 rsample authors
3+
Copyright (c) 2025 rsample authors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

NAMESPACE

-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,6 @@ import(vctrs)
422422
importFrom(cli,cli_abort)
423423
importFrom(cli,cli_text)
424424
importFrom(cli,cli_warn)
425-
importFrom(dplyr,"%>%")
426425
importFrom(dplyr,arrange)
427426
importFrom(dplyr,arrange_)
428427
importFrom(dplyr,bind_cols)

R/boot.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ boot_splits <- function(
142142
prop = 1,
143143
times = times,
144144
replace = TRUE
145-
) %>%
145+
) |>
146146
list_rbind()
147147
indices <- split_unnamed(stratas$idx, stratas$rs_id)
148148
}

R/bootci.R

+53-53
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# helpers
55

66
check_includes_apparent <- function(x, call = caller_env()) {
7-
if (x %>% dplyr::filter(id == "Apparent") %>% nrow() != 1) {
7+
if (x |> dplyr::filter(id == "Apparent") |> nrow() != 1) {
88
cli_abort(
99
c(
1010
"The bootstrap resamples must include an apparent sample.",
@@ -59,7 +59,7 @@ check_statistics <- function(x, std_col = FALSE, call = caller_env()) {
5959
list_cols <- names(x)[map_lgl(x, is_list)]
6060
x <- try(tidyr::unnest(x, cols = all_of(list_cols)), silent = TRUE)
6161
} else {
62-
x <- try(map(x, ~.x) %>% list_rbind(), silent = TRUE)
62+
x <- try(map(x, \(.x) .x) |> list_rbind(), silent = TRUE)
6363
}
6464

6565
if (inherits(x, "try-error")) {
@@ -81,8 +81,8 @@ check_statistics <- function(x, std_col = FALSE, call = caller_env()) {
8181
id,
8282
tidyselect::one_of(std_candidates),
8383
dplyr::starts_with(".")
84-
) %>%
85-
mutate(orig = (id == "Apparent")) %>%
84+
) |>
85+
mutate(orig = (id == "Apparent")) |>
8686
dplyr::rename(!!!re_name)
8787
} else {
8888
x <-
@@ -92,14 +92,14 @@ check_statistics <- function(x, std_col = FALSE, call = caller_env()) {
9292
estimate,
9393
tidyselect::one_of(std_candidates),
9494
dplyr::starts_with(".")
95-
) %>%
95+
) |>
9696
dplyr::rename(!!!re_name)
9797
}
9898
} else {
9999
if (has_id) {
100100
x <-
101-
dplyr::select(x, term, estimate, id, dplyr::starts_with(".")) %>%
102-
mutate(orig = (id == "Apparent")) %>%
101+
dplyr::select(x, term, estimate, id, dplyr::starts_with(".")) |>
102+
mutate(orig = (id == "Apparent")) |>
103103
dplyr::select(-id)
104104
} else {
105105
x <- dplyr::select(x, term, estimate, dplyr::starts_with("."))
@@ -113,16 +113,16 @@ check_statistics <- function(x, std_col = FALSE, call = caller_env()) {
113113
get_p0 <- function(x, alpha = 0.05, groups) {
114114
group_sym <- rlang::syms(groups)
115115

116-
orig <- x %>%
117-
group_by(!!!group_sym) %>%
118-
dplyr::filter(orig) %>%
119-
dplyr::select(!!!group_sym, theta_0 = estimate) %>%
116+
orig <- x |>
117+
group_by(!!!group_sym) |>
118+
dplyr::filter(orig) |>
119+
dplyr::select(!!!group_sym, theta_0 = estimate) |>
120120
ungroup()
121-
x %>%
122-
dplyr::filter(!orig) %>%
123-
inner_join(orig, by = groups) %>%
124-
group_by(!!!group_sym) %>%
125-
summarize(p0 = mean(estimate <= theta_0, na.rm = TRUE)) %>%
121+
x |>
122+
dplyr::filter(!orig) |>
123+
inner_join(orig, by = groups) |>
124+
group_by(!!!group_sym) |>
125+
summarize(p0 = mean(estimate <= theta_0, na.rm = TRUE)) |>
126126
mutate(
127127
Z0 = stats::qnorm(p0),
128128
Za = stats::qnorm(1 - alpha / 2)
@@ -148,9 +148,9 @@ check_has_dots <- function(x, call = caller_env()) {
148148

149149
check_num_resamples <- function(x, B = 1000, call = caller_env()) {
150150
x <-
151-
x %>%
152-
dplyr::group_by(term) %>%
153-
dplyr::summarize(n = sum(!is.na(estimate))) %>%
151+
x |>
152+
dplyr::group_by(term) |>
153+
dplyr::summarize(n = sum(!is.na(estimate))) |>
154154
dplyr::filter(n < B)
155155

156156
if (nrow(x) > 0) {
@@ -176,7 +176,7 @@ pctl_single <- function(stats, alpha = 0.05) {
176176
}
177177

178178
# stats is a numeric vector of values
179-
ci <- stats %>% quantile(probs = c(alpha / 2, 1 - alpha / 2), na.rm = TRUE)
179+
ci <- stats |> quantile(probs = c(alpha / 2, 1 - alpha / 2), na.rm = TRUE)
180180

181181
# return a tibble with .lower, .estimate, .upper
182182
res <- tibble(
@@ -240,13 +240,13 @@ pctl_single <- function(stats, alpha = 0.05) {
240240
#' # ------------------------------------------------------------------------------
241241
#'
242242
#' lm_est <- function(split, ...) {
243-
#' lm(mpg ~ disp + hp, data = analysis(split)) %>%
243+
#' lm(mpg ~ disp + hp, data = analysis(split)) |>
244244
#' tidy()
245245
#' }
246246
#'
247247
#' set.seed(52156)
248248
#' car_rs <-
249-
#' bootstraps(mtcars, 500, apparent = TRUE) %>%
249+
#' bootstraps(mtcars, 500, apparent = TRUE) |>
250250
#' mutate(results = map(splits, lm_est))
251251
#'
252252
#' int_pctl(car_rs, results)
@@ -268,8 +268,8 @@ pctl_single <- function(stats, alpha = 0.05) {
268268
#'
269269
#' set.seed(69325)
270270
#' data(Sacramento, package = "modeldata")
271-
#' bootstraps(Sacramento, 1000, apparent = TRUE) %>%
272-
#' mutate(correlations = map(splits, rank_corr)) %>%
271+
#' bootstraps(Sacramento, 1000, apparent = TRUE) |>
272+
#' mutate(correlations = map(splits, rank_corr)) |>
273273
#' int_pctl(correlations)
274274
#'
275275
#' # ------------------------------------------------------------------------------
@@ -278,21 +278,21 @@ pctl_single <- function(stats, alpha = 0.05) {
278278
#'
279279
#' # Get regression estimates for each house type
280280
#' lm_est <- function(split, ...) {
281-
#' analysis(split) %>%
282-
#' tidyr::nest(.by = c(type)) %>%
281+
#' analysis(split) |>
282+
#' tidyr::nest(.by = c(type)) |>
283283
#' # Compute regression estimates for each house type
284284
#' mutate(
285-
#' betas = purrr::map(data, ~ lm(log10(price) ~ sqft, data = .x) %>% tidy())
286-
#' ) %>%
285+
#' betas = purrr::map(data, \(.x) lm(log10(price) ~ sqft, data = .x) |> tidy())
286+
#' ) |>
287287
#' # Convert the column name to begin with a period
288-
#' rename(.type = type) %>%
289-
#' select(.type, betas) %>%
288+
#' rename(.type = type) |>
289+
#' select(.type, betas) |>
290290
#' unnest(cols = betas)
291291
#' }
292292
#'
293293
#' set.seed(52156)
294294
#' house_rs <-
295-
#' bootstraps(Sacramento, 1000, apparent = TRUE) %>%
295+
#' bootstraps(Sacramento, 1000, apparent = TRUE) |>
296296
#' mutate(results = map(splits, lm_est))
297297
#'
298298
#' int_pctl(house_rs, results)
@@ -317,7 +317,7 @@ int_pctl.bootstraps <- function(.data, statistics, alpha = 0.05, ...) {
317317
check_dots_empty()
318318
check_number_decimal(alpha, min = 0, max = 1)
319319

320-
.data <- .data %>% dplyr::filter(id != "Apparent")
320+
.data <- .data |> dplyr::filter(id != "Apparent")
321321

322322
column_name <- tidyselect::vars_select(
323323
names(.data),
@@ -334,9 +334,9 @@ int_pctl.bootstraps <- function(.data, statistics, alpha = 0.05, ...) {
334334
stat_groups <- c("term", grep("^\\.", names(stats), value = TRUE))
335335
stat_groups <- rlang::syms(stat_groups)
336336

337-
vals <- stats %>%
338-
dplyr::group_by(!!!stat_groups) %>%
339-
dplyr::do(pctl_single(.$estimate, alpha = alpha)) %>%
337+
vals <- stats |>
338+
dplyr::group_by(!!!stat_groups) |>
339+
dplyr::do(pctl_single(.$estimate, alpha = alpha)) |>
340340
dplyr::ungroup()
341341
vals
342342
}
@@ -416,16 +416,16 @@ int_t.bootstraps <- function(.data, statistics, alpha = 0.05, ...) {
416416
if (length(column_name) != 1) {
417417
cli_abort(statistics_format_error)
418418
}
419-
stats <- .data %>% dplyr::select(!!column_name, id)
419+
stats <- .data |> dplyr::select(!!column_name, id)
420420
stats <- check_statistics(stats, std_col = TRUE)
421421

422422
check_num_resamples(stats, B = 500)
423423

424424
stat_groups <- c("term", grep("^\\.", names(stats), value = TRUE))
425425
stat_groups <- rlang::syms(stat_groups)
426-
vals <- stats %>%
427-
dplyr::group_by(!!!stat_groups) %>%
428-
dplyr::do(t_single(.$estimate, .$std_err, .$orig, alpha = alpha)) %>%
426+
vals <- stats |>
427+
dplyr::group_by(!!!stat_groups) |>
428+
dplyr::do(t_single(.$estimate, .$std_err, .$orig, alpha = alpha)) |>
429429
dplyr::ungroup()
430430
vals
431431
}
@@ -464,20 +464,20 @@ bca_calc <- function(
464464
cli_abort("{.arg .fn} failed.", call = call)
465465
}
466466

467-
loo_res <- furrr::future_map(loo_rs$splits, .fn, ...) %>% list_rbind()
467+
loo_res <- furrr::future_map(loo_rs$splits, .fn, ...) |> list_rbind()
468468

469469
loo_estimate <-
470-
loo_res %>%
471-
dplyr::group_by(!!!stat_groups_sym) %>%
472-
dplyr::summarize(loo = mean(estimate, na.rm = TRUE)) %>%
473-
dplyr::inner_join(loo_res, by = stat_groups_chr, multiple = "all") %>%
474-
dplyr::group_by(!!!stat_groups_sym) %>%
470+
loo_res |>
471+
dplyr::group_by(!!!stat_groups_sym) |>
472+
dplyr::summarize(loo = mean(estimate, na.rm = TRUE)) |>
473+
dplyr::inner_join(loo_res, by = stat_groups_chr, multiple = "all") |>
474+
dplyr::group_by(!!!stat_groups_sym) |>
475475
dplyr::summarize(
476476
cubed = sum((loo - estimate)^3),
477477
squared = sum((loo - estimate)^2)
478-
) %>%
479-
dplyr::ungroup() %>%
480-
dplyr::inner_join(bias_corr_stats, by = stat_groups_chr) %>%
478+
) |>
479+
dplyr::ungroup() |>
480+
dplyr::inner_join(bias_corr_stats, by = stat_groups_chr) |>
481481
dplyr::mutate(
482482
a = cubed / (6 * (squared^(3 / 2))),
483483
Zu = (Z0 + Za) / (1 - a * (Z0 + Za)) + Z0,
@@ -487,9 +487,9 @@ bca_calc <- function(
487487
)
488488

489489
terms <- loo_estimate$term
490-
stats <- stats %>% dplyr::filter(!orig)
490+
stats <- stats |> dplyr::filter(!orig)
491491

492-
keys <- stats %>% dplyr::distinct(!!!stat_groups_sym)
492+
keys <- stats |> dplyr::distinct(!!!stat_groups_sym)
493493
for (i in seq_len(nrow(keys))) {
494494
tmp_stats <- dplyr::inner_join(stats, keys[i, ], by = stat_groups_chr)
495495
tmp_loo <- dplyr::inner_join(loo_estimate, keys[i, ], by = stat_groups_chr)
@@ -503,8 +503,8 @@ bca_calc <- function(
503503
}
504504
}
505505
ci_bca <-
506-
ci_bca %>%
507-
dplyr::select(!!!stat_groups_sym, .lower, .estimate, .upper) %>%
506+
ci_bca |>
507+
dplyr::select(!!!stat_groups_sym, .lower, .estimate, .upper) |>
508508
dplyr::mutate(
509509
.alpha = alpha,
510510
.method = "BCa"
@@ -538,7 +538,7 @@ int_bca.bootstraps <- function(.data, statistics, alpha = 0.05, .fn, ...) {
538538
if (length(column_name) != 1) {
539539
cli_abort(statistics_format_error)
540540
}
541-
stats <- .data %>% dplyr::select(!!column_name, id, dplyr::starts_with("."))
541+
stats <- .data |> dplyr::select(!!column_name, id, dplyr::starts_with("."))
542542
stats <- check_statistics(stats)
543543

544544
check_num_resamples(stats, B = 1000)

R/labels.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ labels.rsplit <- function(object, ...) {
7878
#' set.seed(363)
7979
#' car_folds <- vfold_cv(mtcars, repeats = 3)
8080
#'
81-
#' analysis(car_folds$splits[[1]]) %>%
82-
#' add_resample_id(car_folds$splits[[1]]) %>%
81+
#' analysis(car_folds$splits[[1]]) |>
82+
#' add_resample_id(car_folds$splits[[1]]) |>
8383
#' head()
8484
#'
8585
#' car_bt <- bootstraps(mtcars)
8686
#'
87-
#' analysis(car_bt$splits[[1]]) %>%
88-
#' add_resample_id(car_bt$splits[[1]]) %>%
87+
#' analysis(car_bt$splits[[1]]) |>
88+
#' add_resample_id(car_bt$splits[[1]]) |>
8989
#' head()
9090
#' @seealso labels.rsplit
9191
#' @export

0 commit comments

Comments
 (0)