Skip to content

Commit 3579521

Browse files
authored
Merge branch 'master' into fix/remove-dead-code-464
2 parents 8bf245f + e8234b4 commit 3579521

File tree

6 files changed

+20
-19
lines changed

6 files changed

+20
-19
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/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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 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)