Skip to content

Commit e1f149d

Browse files
authored
Validate single numeric value for alpha argument (#184)
* Validate single numeric value for alpha argument * Update NEWS for more bootstrap CI alpha fixing
1 parent 861409e commit e1f149d

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

NEWS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
`sliding_index()`, and `sliding_period()`, which have more flexibility than
88
the pre-existing `rolling_origin()`.
99

10-
* Correct passing `alpha` parameter for `int_bca()` (#179).
10+
* Correct `alpha` parameter handling for bootstrap CI functions (#179, #184).
1111

1212
# rsample 0.0.7
1313

R/bootci.R

+9
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ pctl_single <- function(stats, alpha = 0.05) {
239239
int_pctl <- function(.data, statistics, alpha = 0.05) {
240240

241241
check_rset(.data, app = FALSE)
242+
if (length(alpha) != 1 || !is.numeric(alpha)) {
243+
abort("`alpha` must be a single numeric value.")
244+
}
242245

243246
.data <- .data %>% dplyr::filter(id != "Apparent")
244247

@@ -312,6 +315,9 @@ t_single <- function(stats, std_err, is_orig, alpha = 0.05) {
312315
int_t <- function(.data, statistics, alpha = 0.05) {
313316

314317
check_rset(.data)
318+
if (length(alpha) != 1 || !is.numeric(alpha)) {
319+
abort("`alpha` must be a single numeric value.")
320+
}
315321

316322
column_name <- tidyselect::vars_select(names(.data), !!enquo(statistics))
317323
if (length(column_name) != 1) {
@@ -410,6 +416,9 @@ bca_calc <- function(stats, orig_data, alpha = 0.05, .fn, ...) {
410416
int_bca <- function(.data, statistics, alpha = 0.05, .fn, ...) {
411417

412418
check_rset(.data)
419+
if (length(alpha) != 1 || !is.numeric(alpha)) {
420+
abort("`alpha` must be a single numeric value.")
421+
}
413422

414423
has_dots(.fn)
415424

tests/testthat/test_bootci.R

+4
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ context("boot_ci() Input Validation")
206206
test_that("bad input", {
207207
expect_error(int_pctl(bt_small, id))
208208
expect_error(int_pctl(bt_small, junk))
209+
expect_error(int_pctl(bt_small, stats, alpha = c(0.05, 0.2)))
210+
expect_error(int_t(bt_small, stats, alpha = "potato"))
211+
expect_error(int_bca(bt_small, stats, alpha = 1:2, .fn = get_stats))
212+
209213

210214
bad_bt_norm <-
211215
bt_norm %>%

0 commit comments

Comments
 (0)