diff --git a/NEWS.md b/NEWS.md index b223f663..7589d3aa 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # bayesplot (development version) +* Standardize input validation errors in `ppc_km_overlay()` and interpolation helpers to use `rlang::abort()` for consistent error handling. * Fix assignment-in-call bug in `mcmc_rank_ecdf()` (#). * Replaced deprecated `dplyr` and `tidyselect` functions (`top_n`, `one_of`, `group_indices`) with their modern equivalents to ensure future compatibility. (#431) * Documentation added for all exported `*_data()` functions (#209) diff --git a/R/helpers-ppc.R b/R/helpers-ppc.R index e268b315..5206b9af 100644 --- a/R/helpers-ppc.R +++ b/R/helpers-ppc.R @@ -456,7 +456,7 @@ interpolate_gamma <- function(N, K, prob, L) { get_interpolation_values <- function(N, K, L, prob) { for (dim in c("L", "prob")) { if (all(get(dim) != .gamma_adj[, dim])) { - stop(paste( + abort(paste( "No precomputed values to interpolate from for '", dim, "' = ", get(dim), ".\n", @@ -469,7 +469,7 @@ get_interpolation_values <- function(N, K, L, prob) { } vals <- .gamma_adj[.gamma_adj$L == L & .gamma_adj$prob == prob, ] if (N > max(vals$N)) { - stop(paste( + abort(paste( "No precomputed values to interpolate from for sample length of ", N, ".\n", @@ -480,7 +480,7 @@ get_interpolation_values <- function(N, K, L, prob) { )) } if (N < min(vals$N)) { - stop(paste( + abort(paste( "No precomputed values to interpolate from for sample length of ", N, ".\n", @@ -491,7 +491,7 @@ get_interpolation_values <- function(N, K, L, prob) { )) } if (K > max(vals[vals$N <= N, ]$K)) { - stop(paste( + abort(paste( "No precomputed values available for interpolation for 'K' = ", K, ".\n", @@ -502,7 +502,7 @@ get_interpolation_values <- function(N, K, L, prob) { )) } if (K < min(vals[vals$N <= N, ]$K)) { - stop(paste( + abort(paste( "No precomputed values available for interpolation for 'K' = ", K, ".\n", diff --git a/R/ppc-censoring.R b/R/ppc-censoring.R index e41cbae9..d0588a90 100644 --- a/R/ppc-censoring.R +++ b/R/ppc-censoring.R @@ -113,17 +113,17 @@ ppc_km_overlay <- function( suggested_package("ggfortify") if (!is.numeric(status_y) || length(status_y) != length(y) || !all(status_y %in% c(0, 1))) { - stop("`status_y` must be a numeric vector of 0s and 1s the same length as `y`.", call. = FALSE) + abort("`status_y` must be a numeric vector of 0s and 1s the same length as `y`.") } if (!is.null(left_truncation_y)) { if (!is.numeric(left_truncation_y) || length(left_truncation_y) != length(y)) { - stop("`left_truncation_y` must be a numeric vector of the same length as `y`.", call. = FALSE) + abort("`left_truncation_y` must be a numeric vector of the same length as `y`.") } } if (extrapolation_factor < 1) { - stop("`extrapolation_factor` must be greater than or equal to 1.", call. = FALSE) + abort("`extrapolation_factor` must be greater than or equal to 1.") } if (extrapolation_factor == 1.2) { message(