Skip to content

Commit

Permalink
Validate single numeric value for alpha argument (#184)
Browse files Browse the repository at this point in the history
* Validate single numeric value for alpha argument

* Update NEWS for more bootstrap CI alpha fixing
  • Loading branch information
juliasilge authored Sep 14, 2020
1 parent 861409e commit e1f149d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
`sliding_index()`, and `sliding_period()`, which have more flexibility than
the pre-existing `rolling_origin()`.

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

# rsample 0.0.7

Expand Down
9 changes: 9 additions & 0 deletions R/bootci.R
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ pctl_single <- function(stats, alpha = 0.05) {
int_pctl <- function(.data, statistics, alpha = 0.05) {

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

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

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

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

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

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

has_dots(.fn)

Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test_bootci.R
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ context("boot_ci() Input Validation")
test_that("bad input", {
expect_error(int_pctl(bt_small, id))
expect_error(int_pctl(bt_small, junk))
expect_error(int_pctl(bt_small, stats, alpha = c(0.05, 0.2)))
expect_error(int_t(bt_small, stats, alpha = "potato"))
expect_error(int_bca(bt_small, stats, alpha = 1:2, .fn = get_stats))


bad_bt_norm <-
bt_norm %>%
Expand Down

0 comments on commit e1f149d

Please sign in to comment.