Skip to content

Commit 3f4e352

Browse files
authored
Merge pull request #456 from utkarshpawade/fix-stop-vs-abort-inconsistency
Standardize PPC error handling by replacing stop() with rlang abort()
2 parents b1cb851 + 95aa7cc commit 3f4e352

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# bayesplot (development version)
22

3+
* Standardize input validation errors in `ppc_km_overlay()` and interpolation helpers to use `rlang::abort()` for consistent error handling.
34
* Fix assignment-in-call bug in `mcmc_rank_ecdf()` (#).
45
* Replaced deprecated `dplyr` and `tidyselect` functions (`top_n`, `one_of`, `group_indices`) with their modern equivalents to ensure future compatibility. (#431)
56
* Documentation added for all exported `*_data()` functions (#209)

R/helpers-ppc.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ interpolate_gamma <- function(N, K, prob, L) {
456456
get_interpolation_values <- function(N, K, L, prob) {
457457
for (dim in c("L", "prob")) {
458458
if (all(get(dim) != .gamma_adj[, dim])) {
459-
stop(paste(
459+
abort(paste(
460460
"No precomputed values to interpolate from for '", dim, "' = ",
461461
get(dim),
462462
".\n",
@@ -469,7 +469,7 @@ get_interpolation_values <- function(N, K, L, prob) {
469469
}
470470
vals <- .gamma_adj[.gamma_adj$L == L & .gamma_adj$prob == prob, ]
471471
if (N > max(vals$N)) {
472-
stop(paste(
472+
abort(paste(
473473
"No precomputed values to interpolate from for sample length of ",
474474
N,
475475
".\n",
@@ -480,7 +480,7 @@ get_interpolation_values <- function(N, K, L, prob) {
480480
))
481481
}
482482
if (N < min(vals$N)) {
483-
stop(paste(
483+
abort(paste(
484484
"No precomputed values to interpolate from for sample length of ",
485485
N,
486486
".\n",
@@ -491,7 +491,7 @@ get_interpolation_values <- function(N, K, L, prob) {
491491
))
492492
}
493493
if (K > max(vals[vals$N <= N, ]$K)) {
494-
stop(paste(
494+
abort(paste(
495495
"No precomputed values available for interpolation for 'K' = ",
496496
K,
497497
".\n",
@@ -502,7 +502,7 @@ get_interpolation_values <- function(N, K, L, prob) {
502502
))
503503
}
504504
if (K < min(vals[vals$N <= N, ]$K)) {
505-
stop(paste(
505+
abort(paste(
506506
"No precomputed values available for interpolation for 'K' = ",
507507
K,
508508
".\n",

R/ppc-censoring.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,17 @@ ppc_km_overlay <- function(
113113
suggested_package("ggfortify")
114114

115115
if (!is.numeric(status_y) || length(status_y) != length(y) || !all(status_y %in% c(0, 1))) {
116-
stop("`status_y` must be a numeric vector of 0s and 1s the same length as `y`.", call. = FALSE)
116+
abort("`status_y` must be a numeric vector of 0s and 1s the same length as `y`.")
117117
}
118118

119119
if (!is.null(left_truncation_y)) {
120120
if (!is.numeric(left_truncation_y) || length(left_truncation_y) != length(y)) {
121-
stop("`left_truncation_y` must be a numeric vector of the same length as `y`.", call. = FALSE)
121+
abort("`left_truncation_y` must be a numeric vector of the same length as `y`.")
122122
}
123123
}
124124

125125
if (extrapolation_factor < 1) {
126-
stop("`extrapolation_factor` must be greater than or equal to 1.", call. = FALSE)
126+
abort("`extrapolation_factor` must be greater than or equal to 1.")
127127
}
128128
if (extrapolation_factor == 1.2) {
129129
message(

0 commit comments

Comments
 (0)