diff --git a/NEWS.md b/NEWS.md index 7589d3aa..1ef86a53 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # bayesplot (development version) +* Use `rlang::warn()` and `rlang::inform()` for selected PPC user messages instead of base `warning()` and `message()`. * 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) diff --git a/R/ppc-censoring.R b/R/ppc-censoring.R index d0588a90..bcca33d6 100644 --- a/R/ppc-censoring.R +++ b/R/ppc-censoring.R @@ -126,10 +126,10 @@ ppc_km_overlay <- function( abort("`extrapolation_factor` must be greater than or equal to 1.") } if (extrapolation_factor == 1.2) { - message( + inform(paste0( "Note: `extrapolation_factor` now defaults to 1.2 (20%).\n", "To display all posterior predictive draws, set `extrapolation_factor = Inf`." - ) + )) } data <- ppc_data(y, yrep, group = status_y) diff --git a/R/ppc-loo.R b/R/ppc-loo.R index e0f93039..2f91c5b5 100644 --- a/R/ppc-loo.R +++ b/R/ppc-loo.R @@ -202,15 +202,14 @@ ppc_loo_pit_overlay <- function(y, ) if (!missing(y) && all(y %in% 0:1)) { - warning( + warn(paste0( "This plot is not recommended for binary data. ", "For plots that are more suitable see ", - "\nhttps://avehtari.github.io/modelselection/diabetes.html#44_calibration_of_predictions", - call. = FALSE - ) + "\nhttps://avehtari.github.io/modelselection/diabetes.html#44_calibration_of_predictions" + )) } - message(paste( + inform(paste( "NOTE: The kernel density estimate assumes continuous observations", "and is not optimal for discrete observations." )) @@ -797,7 +796,7 @@ ppc_loo_ribbon <- # 1-D Gaussian window filter. This method uses the "reflection method" # to estimate these pvalues and helps speed up the code if (any(is.infinite(x))) { - warning(paste( + warn(paste( "Ignored", sum(is.infinite(x)), "Non-finite PIT values are invalid for KDE boundary correction method" )) diff --git a/R/ppc-test-statistics.R b/R/ppc-test-statistics.R index b4d2043a..73b74769 100644 --- a/R/ppc-test-statistics.R +++ b/R/ppc-test-statistics.R @@ -449,9 +449,9 @@ Tyrep_label <- function() expression(italic(T)(italic(y)[rep])) message_if_using_mean <- function(stat) { if (is.character(stat) && stat == "mean") { - message( + inform(paste0( "Note: in most cases the default test statistic 'mean' is ", "too weak to detect anything of interest." - ) + )) } } diff --git a/tests/testthat/test-ppc-loo.R b/tests/testthat/test-ppc-loo.R index 9381692f..83cdaf50 100644 --- a/tests/testthat/test-ppc-loo.R +++ b/tests/testthat/test-ppc-loo.R @@ -59,6 +59,19 @@ test_that("ppc_loo_pit_overlay works with boundary_correction=FALSE", { expect_gg(p1) }) +test_that(".kde_correction warns when PIT values are non-finite", { + set.seed(123) + pit_vals <- c(stats::runif(500), Inf) + expect_warning( + out <- .kde_correction(pit_vals, bw = "nrd0", grid_len = 128), + "Non-finite PIT values are invalid" + ) + expect_type(out, "list") + expect_true(all(c("xs", "bc_pvals") %in% names(out))) + expect_equal(length(out$xs), 128) + expect_equal(length(out$bc_pvals), 128) +}) + test_that("ppc_loo_pit_qq returns ggplot object", { skip_if_not_installed("rstanarm") skip_if_not_installed("loo")