Skip to content

Commit 861dc2b

Browse files
Merge branch 'master' into fix/drop-pandoc-citeproc-474
2 parents 551fda0 + 05800bd commit 861dc2b

17 files changed

+60
-50
lines changed

.github/workflows/test-coverage.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
1919

2020
steps:
21-
- uses: actions/checkout@v4
21+
- uses: actions/checkout@v6
2222

2323
- uses: r-lib/actions/setup-r@v2
2424
with:

NEWS.md

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

3+
* Use `rlang::warn()` and `rlang::inform()` for selected PPC user messages instead of base `warning()` and `message()`.
4+
* Standardize input validation errors in `ppc_km_overlay()` and interpolation helpers to use `rlang::abort()` for consistent error handling.
35
* Fix assignment-in-call bug in `mcmc_rank_ecdf()` (#).
46
* Replaced deprecated `dplyr` and `tidyselect` functions (`top_n`, `one_of`, `group_indices`) with their modern equivalents to ensure future compatibility. (#431)
57
* Documentation added for all exported `*_data()` functions (#209)
@@ -8,6 +10,7 @@
810
* Fixed test in `test-ppc-distributions.R` that incorrectly used `ppc_dens()` instead of `ppd_dens()` when testing PPD functions
911
* New functions `mcmc_dots` and `mcmc_dots_by_chain` for dot plots of MCMC draws by @behramulukir (#402)
1012
* Default to `quantiles=100` for all dot plots by @behramulukir (#402)
13+
* Use `"neff_ratio"` consistently in diagnostic color scale helpers to avoid relying on partial matching of `"neff"`.
1114

1215
# bayesplot 1.15.0
1316

R/bayesplot-colors.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ color_scheme_view <- function(scheme = NULL) {
189189

190190
#' @export
191191
print.bayesplot_scheme <- function(x, ...) {
192-
tab <- data.frame(unlist(x, use.names = FALSE), stringsAsFactors = FALSE)
192+
tab <- data.frame(unlist(x, use.names = FALSE))
193193
colnames(tab) <- attr(x, "scheme_name") %||% "hex_color"
194194
print(tab, ...)
195195
}

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/mcmc-diagnostics.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ mcmc_neff <- function(ratio, ..., size = NULL) {
255255
linetype = 2,
256256
linewidth = 0.25) +
257257
labs(y = NULL, x = expression(N[eff]/N)) +
258-
scale_fill_diagnostic("neff") +
259-
scale_color_diagnostic("neff") +
258+
scale_fill_diagnostic("neff_ratio") +
259+
scale_color_diagnostic("neff_ratio") +
260260
scale_x_continuous(
261261
breaks = breaks,
262262
# as.character truncates trailing zeroes, while ggplot default does not
@@ -287,8 +287,8 @@ mcmc_neff_hist <- function(ratio, ..., binwidth = NULL, bins = NULL, breaks = NU
287287
binwidth = binwidth,
288288
bins = bins,
289289
breaks = breaks) +
290-
scale_color_diagnostic("neff") +
291-
scale_fill_diagnostic("neff") +
290+
scale_color_diagnostic("neff_ratio") +
291+
scale_fill_diagnostic("neff_ratio") +
292292
labs(x = expression(N[eff]/N), y = NULL) +
293293
dont_expand_y_axis(c(0.005, 0)) +
294294
yaxis_title(FALSE) +
@@ -424,12 +424,12 @@ diagnostic_points <- function(size = NULL) {
424424

425425
# Functions wrapping around scale_color_manual() and scale_fill_manual(), used to
426426
# color the intervals by rhat value
427-
scale_color_diagnostic <- function(diagnostic = c("rhat", "neff")) {
427+
scale_color_diagnostic <- function(diagnostic = c("rhat", "neff_ratio")) {
428428
d <- match.arg(diagnostic)
429429
diagnostic_color_scale(d, aesthetic = "color")
430430
}
431431

432-
scale_fill_diagnostic <- function(diagnostic = c("rhat", "neff")) {
432+
scale_fill_diagnostic <- function(diagnostic = c("rhat", "neff_ratio")) {
433433
d <- match.arg(diagnostic)
434434
diagnostic_color_scale(d, aesthetic = "fill")
435435
}

R/mcmc-parcoord.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ mcmc_parcoord <-
132132

133133

134134
divg <- sym("Divergent")
135-
draws <- dplyr::filter(data, UQ(divg) == 0)
136-
div_draws <- dplyr::filter(data, UQ(divg) == 1)
135+
draws <- dplyr::filter(data, !!divg == 0)
136+
div_draws <- dplyr::filter(data, !!divg == 1)
137137
has_divs <- isTRUE(nrow(div_draws) > 0)
138138

139139
graph <- ggplot(draws, aes(
@@ -191,7 +191,7 @@ mcmc_parcoord_data <-
191191
# 'Parameter' and 'Value' so need to be a little careful)
192192
divs <- np %>%
193193
validate_nuts_data_frame() %>%
194-
dplyr::filter(UQ(param) == "divergent__") %>%
194+
dplyr::filter(!!param == "divergent__") %>%
195195
select(- !!param) %>%
196196
rename("Divergent" = !!value)
197197

R/mcmc-scatterplots.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@
9898
#' )
9999
#'
100100
#' # add ellipse
101-
#' p + stat_ellipse(level = 0.9, color = "gray20", size = 1)
101+
#' p + stat_ellipse(level = 0.9, color = "gray20", linewidth = 1)
102102
#'
103103
#' # add contour
104104
#' color_scheme_set("red")
105105
#' p2 <- mcmc_scatter(x, pars = c("alpha", "sigma"), size = 3.5, alpha = 0.25)
106-
#' p2 + stat_density_2d(color = "black", size = .5)
106+
#' p2 + stat_density_2d(color = "black", linewidth = .5)
107107
#'
108108
#' # can also add lines/smooths
109109
#' color_scheme_set("pink")
@@ -352,10 +352,10 @@ mcmc_pairs <- function(x,
352352
param <- sym("Parameter")
353353
val <- sym("Value")
354354
np <- validate_nuts_data_frame(np, lp)
355-
divs <- dplyr::filter(np, UQ(param) == "divergent__") %>% pull(UQ(val))
355+
divs <- dplyr::filter(np, !!param == "divergent__") %>% pull(!!val)
356356
divergent__ <- matrix(divs, nrow = n_iter * n_chain, ncol = n_param)[, 1]
357357
if (!no_max_td) {
358-
gt_max_td <- (dplyr::filter(np, UQ(param) == "treedepth__") %>% pull(UQ(val))) >= max_treedepth
358+
gt_max_td <- (dplyr::filter(np, !!param == "treedepth__") %>% pull(!!val)) >= max_treedepth
359359
max_td_hit__ <- matrix(gt_max_td, nrow = n_iter * n_chain, ncol = n_param)[, 1]
360360
}
361361
}
@@ -674,11 +674,11 @@ pairs_condition <- function(chains = NULL, draws = NULL, nuts = NULL) {
674674
divg <- sym("Divergent")
675675
xydata$Divergent <-
676676
np %>%
677-
dplyr::filter(UQ(param) == "divergent__") %>%
678-
pull(UQ(val))
677+
dplyr::filter(!!param == "divergent__") %>%
678+
pull(!!val)
679679

680-
divdata <- dplyr::filter(xydata, UQ(divg) == 1)
681-
xydata <- dplyr::filter(xydata, UQ(divg) == 0)
680+
divdata <- dplyr::filter(xydata, !!divg == 1)
681+
xydata <- dplyr::filter(xydata, !!divg == 0)
682682
}
683683

684684
graph <- ggplot(data = xydata, aes(x = .data$x, y = .data$y)) +
@@ -880,7 +880,7 @@ handle_condition <- function(x, condition=NULL, np=NULL, lp=NULL) {
880880

881881
} else {
882882
param <- sym("Parameter")
883-
mark <- dplyr::filter(np, UQ(param) == condition)
883+
mark <- dplyr::filter(np, !!param == condition)
884884
mark <- unstack_to_matrix(mark, Value ~ Chain)
885885
}
886886
if (condition == "divergent__") {

R/mcmc-traces.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ mcmc_trace_data <- function(x,
719719
color = guide_legend(order = 1),
720720
linetype = guide_legend(
721721
order = 2, title = NULL, keywidth = rel(1/2),
722-
override.aes = list(size = rel(1/2)))
722+
override.aes = list(linewidth = rel(1/2)))
723723
)
724724
}
725725
}
@@ -789,7 +789,7 @@ divergence_rug <- function(np, np_style, n_iter, n_chain) {
789789
divg <- sym("Divergent")
790790

791791
div_info <- np %>%
792-
dplyr::filter(UQ(param) == "divergent__") %>%
792+
dplyr::filter(!!param == "divergent__") %>%
793793
group_by(!! iter) %>%
794794
summarise(
795795
Divergent = ifelse(sum(!! val) > 0, !! iter, NA)

R/ppc-censoring.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,23 @@ 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) {
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
))

0 commit comments

Comments
 (0)