Skip to content

Commit 6801047

Browse files
authored
Merge pull request #462 from utkarshpawade/warning-message-vs-warn-inform-inconsistency
Standardize PPC messages to warn/inform
2 parents 6454b79 + 7fb682e commit 6801047

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
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+
* Use `rlang::warn()` and `rlang::inform()` for selected PPC user messages instead of base `warning()` and `message()`.
34
* Standardize input validation errors in `ppc_km_overlay()` and interpolation helpers to use `rlang::abort()` for consistent error handling.
45
* Fix assignment-in-call bug in `mcmc_rank_ecdf()` (#).
56
* Replaced deprecated `dplyr` and `tidyselect` functions (`top_n`, `one_of`, `group_indices`) with their modern equivalents to ensure future compatibility. (#431)

R/ppc-censoring.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ ppc_km_overlay <- function(
126126
abort("`extrapolation_factor` must be greater than or equal to 1.")
127127
}
128128
if (extrapolation_factor == 1.2) {
129-
message(
129+
inform(paste0(
130130
"Note: `extrapolation_factor` now defaults to 1.2 (20%).\n",
131131
"To display all posterior predictive draws, set `extrapolation_factor = Inf`."
132-
)
132+
))
133133
}
134134

135135
data <- ppc_data(y, yrep, group = status_y)

R/ppc-loo.R

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,14 @@ ppc_loo_pit_overlay <- function(y,
202202
)
203203

204204
if (!missing(y) && all(y %in% 0:1)) {
205-
warning(
205+
warn(paste0(
206206
"This plot is not recommended for binary data. ",
207207
"For plots that are more suitable see ",
208-
"\nhttps://avehtari.github.io/modelselection/diabetes.html#44_calibration_of_predictions",
209-
call. = FALSE
210-
)
208+
"\nhttps://avehtari.github.io/modelselection/diabetes.html#44_calibration_of_predictions"
209+
))
211210
}
212211

213-
message(paste(
212+
inform(paste(
214213
"NOTE: The kernel density estimate assumes continuous observations",
215214
"and is not optimal for discrete observations."
216215
))
@@ -797,7 +796,7 @@ ppc_loo_ribbon <-
797796
# 1-D Gaussian window filter. This method uses the "reflection method"
798797
# to estimate these pvalues and helps speed up the code
799798
if (any(is.infinite(x))) {
800-
warning(paste(
799+
warn(paste(
801800
"Ignored", sum(is.infinite(x)),
802801
"Non-finite PIT values are invalid for KDE boundary correction method"
803802
))

R/ppc-test-statistics.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,9 @@ Tyrep_label <- function() expression(italic(T)(italic(y)[rep]))
449449

450450
message_if_using_mean <- function(stat) {
451451
if (is.character(stat) && stat == "mean") {
452-
message(
452+
inform(paste0(
453453
"Note: in most cases the default test statistic 'mean' is ",
454454
"too weak to detect anything of interest."
455-
)
455+
))
456456
}
457457
}

tests/testthat/test-ppc-loo.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ test_that("ppc_loo_pit_overlay works with boundary_correction=FALSE", {
5959
expect_gg(p1)
6060
})
6161

62+
test_that(".kde_correction warns when PIT values are non-finite", {
63+
set.seed(123)
64+
pit_vals <- c(stats::runif(500), Inf)
65+
expect_warning(
66+
out <- .kde_correction(pit_vals, bw = "nrd0", grid_len = 128),
67+
"Non-finite PIT values are invalid"
68+
)
69+
expect_type(out, "list")
70+
expect_true(all(c("xs", "bc_pvals") %in% names(out)))
71+
expect_equal(length(out$xs), 128)
72+
expect_equal(length(out$bc_pvals), 128)
73+
})
74+
6275
test_that("ppc_loo_pit_qq returns ggplot object", {
6376
skip_if_not_installed("rstanarm")
6477
skip_if_not_installed("loo")

0 commit comments

Comments
 (0)