Skip to content

Commit 96eb581

Browse files
Merge branch 'master' into fix-stop-vs-abort-inconsistency
2 parents 049b171 + 3ac1b5e commit 96eb581

43 files changed

Lines changed: 369 additions & 142 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test-coverage.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ on:
77

88
name: test-coverage.yaml
99

10-
permissions: read-all
10+
permissions:
11+
contents: read
12+
id-token: write
1113

1214
jobs:
1315
test-coverage:
@@ -45,7 +47,7 @@ jobs:
4547
files: ./cobertura.xml
4648
plugins: noop
4749
disable_search: true
48-
token: ${{ secrets.CODECOV_TOKEN }}
50+
use_oidc: true
4951

5052
- name: Show testthat output
5153
if: always()
@@ -56,7 +58,7 @@ jobs:
5658

5759
- name: Upload test results
5860
if: failure()
59-
uses: actions/upload-artifact@v4
61+
uses: actions/upload-artifact@v7
6062
with:
6163
name: coverage-test-failures
6264
path: ${{ runner.temp }}/package

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ SystemRequirements: pandoc (>= 1.12.3), pandoc-citeproc
3030
Depends:
3131
R (>= 4.1.0)
3232
Imports:
33-
dplyr (>= 0.8.0),
33+
dplyr (>= 1.0.0),
3434
ggplot2 (>= 3.4.0),
3535
ggridges (>= 0.5.5),
3636
glue,
37+
lifecycle,
3738
posterior,
3839
reshape2,
3940
rlang (>= 0.3.0),

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,6 @@ importFrom(dplyr,top_n)
226226
importFrom(dplyr,ungroup)
227227
importFrom(dplyr,vars)
228228
importFrom(ggplot2,"%+replace%")
229+
importFrom(lifecycle,deprecate_warn)
230+
importFrom(lifecycle,deprecated)
231+
importFrom(lifecycle,is_present)

NEWS.md

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

33
* Standardize input validation errors in `ppc_km_overlay()` and interpolation helpers to use `rlang::abort()` for consistent error handling.
4+
* Fix assignment-in-call bug in `mcmc_rank_ecdf()` (#).
5+
* Replaced deprecated `dplyr` and `tidyselect` functions (`top_n`, `one_of`, `group_indices`) with their modern equivalents to ensure future compatibility. (#431)
6+
* Documentation added for all exported `*_data()` functions (#209)
7+
* Improved documentation for `binwidth`, `bins`, and `breaks` arguments to clarify they are passed to `ggplot2::geom_area()` and `ggdist::stat_dots()` in addition to `ggplot2::geom_histogram()`
8+
* Improved documentation for `freq` argument to clarify it applies to frequency polygons in addition to histograms
9+
* Fixed test in `test-ppc-distributions.R` that incorrectly used `ppc_dens()` instead of `ppd_dens()` when testing PPD functions
410
* New functions `mcmc_dots` and `mcmc_dots_by_chain` for dot plots of MCMC draws by @behramulukir (#402)
511
* Default to `quantiles=100` for all dot plots by @behramulukir (#402)
612

R/bayesplot-helpers.R

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -446,19 +446,28 @@ plot_bg <- function(on = TRUE, ...) {
446446

447447
#' @rdname bayesplot-helpers
448448
#' @export
449-
#' @param color,size Passed to [ggplot2::element_line()].
450-
#'
451-
grid_lines <- function(color = "gray50", size = 0.2) {
449+
#' @param color,linewidth Passed to [ggplot2::element_line()].
450+
#' @param size `r lifecycle::badge("deprecated")` Use `linewidth` instead.
451+
#'
452+
grid_lines <- function(color = "gray50", linewidth = 0.2, size = deprecated()) {
453+
if (lifecycle::is_present(size)) {
454+
lifecycle::deprecate_warn(
455+
"1.16.0",
456+
"grid_lines(size)",
457+
"grid_lines(linewidth)"
458+
)
459+
linewidth <- size
460+
}
452461
theme(
453-
panel.grid.major = element_line(color = color, linewidth = size),
454-
panel.grid.minor = element_line(color = color, linewidth = size * 0.5)
462+
panel.grid.major = element_line(color = color, linewidth = linewidth),
463+
panel.grid.minor = element_line(color = color, linewidth = linewidth * 0.5)
455464
)
456465
}
457466

458-
grid_lines_y <- function(color = "gray50", size = 0.2) {
467+
grid_lines_y <- function(color = "gray50", linewidth = 0.2) {
459468
theme(
460-
panel.grid.major.y = element_line(color = color, linewidth = size),
461-
panel.grid.minor.y = element_line(color = color, linewidth = size * 0.5)
469+
panel.grid.major.y = element_line(color = color, linewidth = linewidth),
470+
panel.grid.minor.y = element_line(color = color, linewidth = linewidth * 0.5)
462471
)
463472
}
464473

R/bayesplot-package.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#'
66
#' @import ggplot2 stats rlang
77
#' @importFrom dplyr %>% summarise group_by select
8+
#' @importFrom lifecycle deprecated deprecate_warn is_present
89
#'
910
#' @description
1011
#' \if{html}{

R/helpers-gg.R

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,10 @@ geom_ignore <- function(...) {
2424

2525
#' Add new aesthetic mappings to a list of aesthetic mappings
2626
#'
27-
#' @param mapping a list of `uneval` aesthetic mappings (created by `aes_()`)
28-
#' @param ... additional mappings to add, e.g., `color = ~ parameter`
27+
#' @param mapping a list of `uneval` aesthetic mappings (created by `aes()`)
28+
#' @param ... additional mappings to add using `.data$` syntax
2929
#' @return the updated list
3030
#' @noRd
31-
modify_aes_ <- function(mapping, ...) {
32-
utils::modifyList(mapping, aes_(...))
33-
}
34-
35-
#' Same as `modify_aes_` but using `aes()` instead of `aes_()` (now deprecated).
36-
#' Often `...` will need to contain expression of the form `.data$x` to avoid R cmd check warnings
37-
#' @noRd
3831
modify_aes <- function(mapping, ...) {
3932
utils::modifyList(mapping, aes(...))
4033
}

R/mcmc-diagnostics.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
#'
1919
#' @section Plot Descriptions:
2020
#' \describe{
21+
#' \item{`mcmc_rhat_data()`, `mcmc_neff_data()`}{
22+
#' Data-preparation back ends for the R-hat and effective sample size plots.
23+
#' Users can call these functions directly to obtain the data frame of
24+
#' diagnostic values with rating labels and create custom diagnostic
25+
#' visualizations with **ggplot2**.
26+
#' }
27+
#'
2128
#' \item{`mcmc_rhat()`, `mcmc_rhat_hist()`}{
2229
#' Rhat values as either points or a histogram. Values are colored using
2330
#' different shades (lighter is better). The chosen thresholds are somewhat
@@ -70,7 +77,7 @@
7077
#' (p <- mcmc_acf_bar(x, pars = c("alpha", "beta[1]")))
7178
#'
7279
#' # add horiztonal dashed line at 0.5
73-
#' p + hline_at(0.5, linetype = 2, size = 0.15, color = "gray")
80+
#' p + hline_at(0.5, linetype = 2, linewidth = 0.15, color = "gray")
7481
#' }
7582
#'
7683
#' # fake rhat values to use for demonstration

R/mcmc-distributions.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#' @param ... For dot plots, optional additional arguments to pass to [ggdist::stat_dots()].
1616
#' @param alpha Passed to the geom to control the transparency.
1717
#'
18-
#' @template return-ggplot
18+
#' @template return-ggplot-or-data
1919
#'
2020
#' @section Plot Descriptions:
2121
#' \describe{
@@ -48,6 +48,12 @@
4848
#' appear in separate facets; in `mcmc_dens_chains()` they appear in the
4949
#' same panel and can overlap vertically.
5050
#' }
51+
#' \item{`mcmc_dens_chains_data()`}{
52+
#' Data-preparation back end for `mcmc_dens_chains()`. Users can call this
53+
#' function directly to obtain the prepared long-format data frame of MCMC
54+
#' draws (with chain information retained) and create custom visualizations
55+
#' with **ggplot2**.
56+
#' }
5157
#' }
5258
#'
5359
#' @examples
@@ -483,7 +489,7 @@ mcmc_dots_by_chain <- function(
483489
data <- melt_mcmc(x, value.name = "value")
484490
n_param <- num_params(data)
485491

486-
graph <- ggplot(data, aes(x = ~ value)) +
492+
graph <- ggplot(data, aes(x = .data$value)) +
487493
geom_histogram(
488494
set_hist_aes(freq),
489495
fill = get_color("mid"),

R/mcmc-intervals.R

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@
5151
#' ridgelines. This plot provides a compact display of (hierarchically)
5252
#' related distributions.
5353
#' }
54+
#' \item{`mcmc_intervals_data()`, `mcmc_areas_data()`, `mcmc_areas_ridges_data()`}{
55+
#' Data-preparation back ends for `mcmc_intervals()`, `mcmc_areas()`, and
56+
#' `mcmc_areas_ridges()`, respectively. Users can call these functions
57+
#' directly to obtain the prepared data frames of posterior interval
58+
#' summaries and create custom interval or density-area visualizations
59+
#' with **ggplot2**.
60+
#' }
5461
#' }
5562
#'
5663
#' @examples
@@ -640,7 +647,7 @@ mcmc_intervals_data <- function(x,
640647

641648
rhat_tbl <- rhat %>%
642649
mcmc_rhat_data() %>%
643-
select(one_of("parameter"),
650+
select(all_of("parameter"),
644651
rhat_value = "value",
645652
rhat_rating = "rating",
646653
rhat_description = "description") %>%
@@ -656,7 +663,7 @@ mcmc_intervals_data <- function(x,
656663
# Don't import `filter`: otherwise, you get a warning when using
657664
# `devtools::load_all(".")` because stats also has a `filter` function
658665

659-
#' @importFrom dplyr inner_join one_of top_n
666+
#' @importFrom dplyr inner_join all_of slice_min
660667
#' @rdname MCMC-intervals
661668
#' @export
662669
mcmc_areas_data <- function(x,
@@ -729,14 +736,14 @@ mcmc_areas_data <- function(x,
729736

730737
# Find the density values closest to the point estimate
731738
point_ests <- intervals %>%
732-
select(one_of("parameter", "m"))
739+
select(all_of(c("parameter", "m")))
733740

734741
point_centers <- data_inner %>%
735742
inner_join(point_ests, by = "parameter") %>%
736743
group_by(.data$parameter) %>%
737744
mutate(diff = abs(.data$m - .data$x)) %>%
738-
dplyr::top_n(1, -.data$diff) %>%
739-
select(one_of("parameter", "x", "m")) %>%
745+
dplyr::slice_min(order_by = .data$diff, n = 1) %>%
746+
select(all_of(c("parameter", "x", "m"))) %>%
740747
rename(center = "x") %>%
741748
ungroup()
742749

@@ -758,15 +765,15 @@ mcmc_areas_data <- function(x,
758765
}
759766

760767
data <- dplyr::bind_rows(data_inner, data_outer, points) %>%
761-
select(one_of("parameter", "interval", "interval_width",
762-
"x", "density", "scaled_density")) %>%
768+
select(all_of(c("parameter", "interval", "interval_width",
769+
"x", "density", "scaled_density"))) %>%
763770
# Density scaled so the highest in entire dataframe has height 1
764771
mutate(plotting_density = .data$density / max(.data$density))
765772

766773
if (rlang::has_name(intervals, "rhat_value")) {
767774
rhat_info <- intervals %>%
768-
select(one_of("parameter", "rhat_value",
769-
"rhat_rating", "rhat_description"))
775+
select(all_of(c("parameter", "rhat_value",
776+
"rhat_rating", "rhat_description")))
770777
data <- inner_join(data, rhat_info, by = "parameter")
771778
}
772779
data
@@ -817,18 +824,15 @@ compute_column_density <- function(df, group_vars, value_var, ...) {
817824
syms()
818825

819826
# Tuck away the subgroups to compute densities on into nested dataframes
820-
sub_df <- dplyr::select(df, !!! group_cols, !! value_var)
821-
822827
group_df <- df %>%
823828
dplyr::select(!!! group_cols, !! value_var) %>%
824829
group_by(!!! group_cols)
825830

826831
by_group <- group_df %>%
827-
split(dplyr::group_indices(group_df)) %>%
832+
dplyr::group_split() %>%
828833
lapply(pull, !! value_var)
829834

830-
nested <- df %>%
831-
dplyr::distinct(!!! group_cols) %>%
835+
nested <- dplyr::group_keys(group_df) %>%
832836
mutate(data = by_group)
833837

834838
nested$density <- lapply(nested$data, compute_interval_density, ...)

0 commit comments

Comments
 (0)