diff --git a/R/bootci.R b/R/bootci.R index a7d45c01..417a1955 100644 --- a/R/bootci.R +++ b/R/bootci.R @@ -359,7 +359,7 @@ t_single <- function(stats, std_err, is_orig, alpha = 0.05) { "{.arg is_orig} should be a logical column the same length as {.arg stats} with no missing values." ) } - if (length(stats) != length(std_err) && length(stats) != length(is_orig)) { + if (length(stats) != length(std_err) || length(stats) != length(is_orig)) { function_args <- c('stats', 'std_err', 'is_orig') cli_abort("{.arg {function_args}} should have the same length.") } diff --git a/man/bootstraps.Rd b/man/bootstraps.Rd index a0c5aeb2..f56a4d8a 100644 --- a/man/bootstraps.Rd +++ b/man/bootstraps.Rd @@ -66,7 +66,7 @@ which are then used to stratify. Strata below 10\% of the total are pooled together; see \code{\link[=make_strata]{make_strata()}} for more details. } \examples{ -\dontshow{if (rlang::is_installed("modeldata")) withAutoprint(\{ # examplesIf} +\dontshow{if (rlang::is_installed("modeldata")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} bootstraps(mtcars, times = 2) bootstraps(mtcars, times = 2, apparent = TRUE) diff --git a/man/clustering_cv.Rd b/man/clustering_cv.Rd index 28bc65e5..3081335a 100644 --- a/man/clustering_cv.Rd +++ b/man/clustering_cv.Rd @@ -71,7 +71,7 @@ The function should return a vector of cluster assignments of length row of the data frame. } \examples{ -\dontshow{if (rlang::is_installed("modeldata")) withAutoprint(\{ # examplesIf} +\dontshow{if (rlang::is_installed("modeldata")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} data(ames, package = "modeldata") clustering_cv(ames, vars = c(Sale_Price, First_Flr_SF, Second_Flr_SF), v = 2) \dontshow{\}) # examplesIf} diff --git a/man/group_bootstraps.Rd b/man/group_bootstraps.Rd index 4f519e45..9a3c7878 100644 --- a/man/group_bootstraps.Rd +++ b/man/group_bootstraps.Rd @@ -64,7 +64,7 @@ original data set. This can be required for some types of analysis of the bootstrap results. } \examples{ -\dontshow{if (rlang::is_installed("modeldata")) withAutoprint(\{ # examplesIf} +\dontshow{if (rlang::is_installed("modeldata")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} data(ames, package = "modeldata") set.seed(13) diff --git a/man/group_mc_cv.Rd b/man/group_mc_cv.Rd index f0c087bf..d05ccdd1 100644 --- a/man/group_mc_cv.Rd +++ b/man/group_mc_cv.Rd @@ -52,7 +52,7 @@ A common use of this kind of resampling is when you have repeated measures of the same subject. } \examples{ -\dontshow{if (rlang::is_installed("modeldata")) withAutoprint(\{ # examplesIf} +\dontshow{if (rlang::is_installed("modeldata")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} data(ames, package = "modeldata") set.seed(123) diff --git a/man/group_vfold_cv.Rd b/man/group_vfold_cv.Rd index 9b198779..0f2796f9 100644 --- a/man/group_vfold_cv.Rd +++ b/man/group_vfold_cv.Rd @@ -61,7 +61,7 @@ out at a time. A common use of this kind of resampling is when you have repeated measures of the same subject. } \examples{ -\dontshow{if (rlang::is_installed("modeldata")) withAutoprint(\{ # examplesIf} +\dontshow{if (rlang::is_installed("modeldata")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} data(ames, package = "modeldata") set.seed(123) diff --git a/man/initial_split.Rd b/man/initial_split.Rd index b589a831..d339e305 100644 --- a/man/initial_split.Rd +++ b/man/initial_split.Rd @@ -86,7 +86,7 @@ which are then used to stratify. Strata below 10\% of the total are pooled together; see \code{\link[=make_strata]{make_strata()}} for more details. } \examples{ -\dontshow{if (rlang::is_installed("modeldata")) withAutoprint(\{ # examplesIf} +\dontshow{if (rlang::is_installed("modeldata")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} set.seed(1353) car_split <- initial_split(mtcars) train_data <- training(car_split) diff --git a/man/initial_validation_split.Rd b/man/initial_validation_split.Rd index be0a94c2..9017e36e 100644 --- a/man/initial_validation_split.Rd +++ b/man/initial_validation_split.Rd @@ -97,7 +97,7 @@ which are then used to stratify. Strata below 10\% of the total are pooled together; see \code{\link[=make_strata]{make_strata()}} for more details. } \examples{ -\dontshow{if (rlang::is_installed("modeldata")) withAutoprint(\{ # examplesIf} +\dontshow{if (rlang::is_installed("modeldata")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} set.seed(1353) car_split <- initial_validation_split(mtcars) train_data <- training(car_split) diff --git a/man/int_pctl.Rd b/man/int_pctl.Rd index 9c09e980..fa01c1e7 100644 --- a/man/int_pctl.Rd +++ b/man/int_pctl.Rd @@ -75,7 +75,7 @@ that was used to create the statistics of interest and are computationally taxing. } \examples{ -\dontshow{if (rlang::is_installed("broom") & rlang::is_installed("modeldata")) withAutoprint(\{ # examplesIf} +\dontshow{if (rlang::is_installed("broom") & rlang::is_installed("modeldata")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} \donttest{ library(broom) library(dplyr) diff --git a/man/mc_cv.Rd b/man/mc_cv.Rd index 9755b1fd..1f928783 100644 --- a/man/mc_cv.Rd +++ b/man/mc_cv.Rd @@ -47,7 +47,7 @@ which are then used to stratify. Strata below 10\% of the total are pooled together; see \code{\link[=make_strata]{make_strata()}} for more details. } \examples{ -\dontshow{if (rlang::is_installed("modeldata")) withAutoprint(\{ # examplesIf} +\dontshow{if (rlang::is_installed("modeldata")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} mc_cv(mtcars, times = 2) mc_cv(mtcars, prop = .5, times = 2) diff --git a/man/reg_intervals.Rd b/man/reg_intervals.Rd index d10a9c42..afc386e9 100644 --- a/man/reg_intervals.Rd +++ b/man/reg_intervals.Rd @@ -49,7 +49,7 @@ called ".replicates" is also returned. A convenience function for confidence intervals with linear-ish parametric models } \examples{ -\dontshow{if (rlang::is_installed("broom")) withAutoprint(\{ # examplesIf} +\dontshow{if (rlang::is_installed("broom")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} \donttest{ set.seed(1) reg_intervals(mpg ~ I(1 / sqrt(disp)), data = mtcars) diff --git a/man/rolling_origin.Rd b/man/rolling_origin.Rd index 8978fb71..9c78bba3 100644 --- a/man/rolling_origin.Rd +++ b/man/rolling_origin.Rd @@ -67,7 +67,7 @@ will make the analysis data set to operate on \emph{weeks} instead of days. The assessment set size is not affected by this option. } \examples{ -\dontshow{if (rlang::is_installed("modeldata")) withAutoprint(\{ # examplesIf} +\dontshow{if (rlang::is_installed("modeldata")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} set.seed(1131) ex_data <- data.frame(row = 1:20, some_var = rnorm(20)) dim(rolling_origin(ex_data)) diff --git a/man/rsample-package.Rd b/man/rsample-package.Rd index d97cec8c..d63be52c 100644 --- a/man/rsample-package.Rd +++ b/man/rsample-package.Rd @@ -33,7 +33,7 @@ Authors: Other contributors: \itemize{ - \item Posit Software, PBC (\href{https://ror.org/03wc8by49}{ROR}) [copyright holder, funder] + \item Posit Software, PBC (03wc8by49) [copyright holder, funder] } } diff --git a/man/slide-resampling.Rd b/man/slide-resampling.Rd index 88f8c7e7..cb54a2ee 100644 --- a/man/slide-resampling.Rd +++ b/man/slide-resampling.Rd @@ -163,7 +163,7 @@ windows from daily data. } } \examples{ -\dontshow{if (rlang::is_installed("modeldata")) withAutoprint(\{ # examplesIf} +\dontshow{if (rlang::is_installed("modeldata")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(vctrs) library(tibble) library(modeldata) diff --git a/man/tidy.rsplit.Rd b/man/tidy.rsplit.Rd index 6dc8f672..3f2bec7f 100644 --- a/man/tidy.rsplit.Rd +++ b/man/tidy.rsplit.Rd @@ -43,7 +43,7 @@ named \code{inner_Row}, are \emph{relative} row indices and do not correspond to rows in the original data set. } \examples{ -\dontshow{if (rlang::is_installed("ggplot2")) withAutoprint(\{ # examplesIf} +\dontshow{if (rlang::is_installed("ggplot2")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(ggplot2) theme_set(theme_bw()) diff --git a/man/validation_split.Rd b/man/validation_split.Rd index 6fc8b3f8..d72118db 100644 --- a/man/validation_split.Rd +++ b/man/validation_split.Rd @@ -79,7 +79,7 @@ which are then used to stratify. Strata below 10\% of the total are pooled together; see \code{\link[=make_strata]{make_strata()}} for more details. } \examples{ -\dontshow{if (rlang::is_installed("modeldata")) withAutoprint(\{ # examplesIf} +\dontshow{if (rlang::is_installed("modeldata")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cars_split <- initial_split(mtcars) cars_not_testing <- training(cars_split) validation_split(cars_not_testing, prop = .9) diff --git a/man/vfold_cv.Rd b/man/vfold_cv.Rd index a1e71fbe..d605b747 100644 --- a/man/vfold_cv.Rd +++ b/man/vfold_cv.Rd @@ -57,7 +57,7 @@ which are then used to stratify. Strata below 10\% of the total are pooled together; see \code{\link[=make_strata]{make_strata()}} for more details. } \examples{ -\dontshow{if (rlang::is_installed("modeldata")) withAutoprint(\{ # examplesIf} +\dontshow{if (rlang::is_installed("modeldata")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} vfold_cv(mtcars, v = 10) vfold_cv(mtcars, v = 10, repeats = 2) diff --git a/tests/testthat/_snaps/bootci.md b/tests/testthat/_snaps/bootci.md index 9f1dd3ca..1a55cd9c 100644 --- a/tests/testthat/_snaps/bootci.md +++ b/tests/testthat/_snaps/bootci.md @@ -190,6 +190,30 @@ Error in `int_pctl()`: ! All statistics must be numeric. +# t_single() errors when stats, std_err, and is_orig lengths mismatch + + Code + rsample:::t_single(stats, std_err[-1], is_orig) + Condition + Error in `rsample:::t_single()`: + ! `stats`, `std_err`, and `is_orig` should have the same length. + +--- + + Code + rsample:::t_single(stats, std_err, is_orig[-1]) + Condition + Error in `rsample:::t_single()`: + ! `stats`, `std_err`, and `is_orig` should have the same length. + +--- + + Code + rsample:::t_single(stats, std_err[-1], is_orig[-1]) + Condition + Error in `rsample:::t_single()`: + ! `stats`, `std_err`, and `is_orig` should have the same length. + # checks for apparent bootstrap Code diff --git a/tests/testthat/test-bootci.R b/tests/testthat/test-bootci.R index 2a7d66ba..751cdcc4 100644 --- a/tests/testthat/test-bootci.R +++ b/tests/testthat/test-bootci.R @@ -291,6 +291,26 @@ test_that("bad input", { }) }) +test_that("t_single() errors when stats, std_err, and is_orig lengths mismatch", { + stats <- rnorm(10) + std_err <- rep(1, 10) + is_orig <- c(TRUE, rep(FALSE, 9)) + + expect_no_error(rsample:::t_single(stats, std_err, is_orig)) + + expect_snapshot(error = TRUE, { + rsample:::t_single(stats, std_err[-1], is_orig) + }) + + expect_snapshot(error = TRUE, { + rsample:::t_single(stats, std_err, is_orig[-1]) + }) + + expect_snapshot(error = TRUE, { + rsample:::t_single(stats, std_err[-1], is_orig[-1]) + }) +}) + test_that("checks for apparent bootstrap", { rs_boot <- bootstraps(mtcars, times = 10, apparent = FALSE) expect_snapshot(error = TRUE, {