From 382b8251bb38479581212c393663aa08eede9850 Mon Sep 17 00:00:00 2001 From: ishaan-arora-1 Date: Tue, 10 Mar 2026 18:27:23 +0530 Subject: [PATCH 1/2] Remove dead modify_aes_() and fix deprecated size usage in helpers - Remove unused modify_aes_() that wrapped the deprecated aes_() (#444) - Rename size param to linewidth in grid_lines() and grid_lines_y() (#445) - Fix doc examples using size where linewidth is expected (#445) Fixes #444, fixes #445 --- R/bayesplot-helpers.R | 14 +++++++------- R/helpers-gg.R | 11 ++--------- R/mcmc-diagnostics.R | 2 +- R/mcmc-scatterplots.R | 2 +- man/MCMC-diagnostics.Rd | 2 +- man/MCMC-scatterplots.Rd | 2 +- man/bayesplot-helpers.Rd | 4 ++-- 7 files changed, 15 insertions(+), 22 deletions(-) diff --git a/R/bayesplot-helpers.R b/R/bayesplot-helpers.R index d3d86ec38..346507a32 100644 --- a/R/bayesplot-helpers.R +++ b/R/bayesplot-helpers.R @@ -446,19 +446,19 @@ plot_bg <- function(on = TRUE, ...) { #' @rdname bayesplot-helpers #' @export -#' @param color,size Passed to [ggplot2::element_line()]. +#' @param color,linewidth Passed to [ggplot2::element_line()]. #' -grid_lines <- function(color = "gray50", size = 0.2) { +grid_lines <- function(color = "gray50", linewidth = 0.2) { theme( - panel.grid.major = element_line(color = color, linewidth = size), - panel.grid.minor = element_line(color = color, linewidth = size * 0.5) + panel.grid.major = element_line(color = color, linewidth = linewidth), + panel.grid.minor = element_line(color = color, linewidth = linewidth * 0.5) ) } -grid_lines_y <- function(color = "gray50", size = 0.2) { +grid_lines_y <- function(color = "gray50", linewidth = 0.2) { theme( - panel.grid.major.y = element_line(color = color, linewidth = size), - panel.grid.minor.y = element_line(color = color, linewidth = size * 0.5) + panel.grid.major.y = element_line(color = color, linewidth = linewidth), + panel.grid.minor.y = element_line(color = color, linewidth = linewidth * 0.5) ) } diff --git a/R/helpers-gg.R b/R/helpers-gg.R index 953a51d4f..21ec794a7 100644 --- a/R/helpers-gg.R +++ b/R/helpers-gg.R @@ -24,17 +24,10 @@ geom_ignore <- function(...) { #' Add new aesthetic mappings to a list of aesthetic mappings #' -#' @param mapping a list of `uneval` aesthetic mappings (created by `aes_()`) -#' @param ... additional mappings to add, e.g., `color = ~ parameter` +#' @param mapping a list of `uneval` aesthetic mappings (created by `aes()`) +#' @param ... additional mappings to add using `.data$` syntax #' @return the updated list #' @noRd -modify_aes_ <- function(mapping, ...) { - utils::modifyList(mapping, aes_(...)) -} - -#' Same as `modify_aes_` but using `aes()` instead of `aes_()` (now deprecated). -#' Often `...` will need to contain expression of the form `.data$x` to avoid R cmd check warnings -#' @noRd modify_aes <- function(mapping, ...) { utils::modifyList(mapping, aes(...)) } diff --git a/R/mcmc-diagnostics.R b/R/mcmc-diagnostics.R index 2727928f2..f363026d3 100644 --- a/R/mcmc-diagnostics.R +++ b/R/mcmc-diagnostics.R @@ -77,7 +77,7 @@ #' (p <- mcmc_acf_bar(x, pars = c("alpha", "beta[1]"))) #' #' # add horiztonal dashed line at 0.5 -#' p + hline_at(0.5, linetype = 2, size = 0.15, color = "gray") +#' p + hline_at(0.5, linetype = 2, linewidth = 0.15, color = "gray") #' } #' #' # fake rhat values to use for demonstration diff --git a/R/mcmc-scatterplots.R b/R/mcmc-scatterplots.R index 4d32391c3..d4f939e1c 100644 --- a/R/mcmc-scatterplots.R +++ b/R/mcmc-scatterplots.R @@ -109,7 +109,7 @@ #' color_scheme_set("pink") #' (p3 <- mcmc_scatter(x, pars = c("alpha", "beta[3]"), alpha = 0.25, size = 3)) #' p3 + geom_smooth(method = "lm", se = FALSE, color = "gray20", -#' size = .75, linetype = 2) +#' linewidth = .75, linetype = 2) #' #' \donttest{ #' if (requireNamespace("hexbin", quietly = TRUE)) { diff --git a/man/MCMC-diagnostics.Rd b/man/MCMC-diagnostics.Rd index 35e589dcb..f6dbad816 100644 --- a/man/MCMC-diagnostics.Rd +++ b/man/MCMC-diagnostics.Rd @@ -163,7 +163,7 @@ color_scheme_set("pink") (p <- mcmc_acf_bar(x, pars = c("alpha", "beta[1]"))) # add horiztonal dashed line at 0.5 -p + hline_at(0.5, linetype = 2, size = 0.15, color = "gray") +p + hline_at(0.5, linetype = 2, linewidth = 0.15, color = "gray") } # fake rhat values to use for demonstration diff --git a/man/MCMC-scatterplots.Rd b/man/MCMC-scatterplots.Rd index e82f0797b..8799e2a0e 100644 --- a/man/MCMC-scatterplots.Rd +++ b/man/MCMC-scatterplots.Rd @@ -313,7 +313,7 @@ p2 + stat_density_2d(color = "black", size = .5) color_scheme_set("pink") (p3 <- mcmc_scatter(x, pars = c("alpha", "beta[3]"), alpha = 0.25, size = 3)) p3 + geom_smooth(method = "lm", se = FALSE, color = "gray20", - size = .75, linetype = 2) + linewidth = .75, linetype = 2) \donttest{ if (requireNamespace("hexbin", quietly = TRUE)) { diff --git a/man/bayesplot-helpers.Rd b/man/bayesplot-helpers.Rd index 897bce928..b668951ea 100644 --- a/man/bayesplot-helpers.Rd +++ b/man/bayesplot-helpers.Rd @@ -63,7 +63,7 @@ panel_bg(on = TRUE, ...) plot_bg(on = TRUE, ...) -grid_lines(color = "gray50", size = 0.2) +grid_lines(color = "gray50", linewidth = 0.2) overlay_function(...) } @@ -112,7 +112,7 @@ example, facet text can be removed by adding \code{facet_text(on=FALSE)}, or simply \code{facet_text(FALSE)} to a ggplot object. If \code{on=TRUE} (the default), then \code{...} can be used to customize the appearance of the theme element.} -\item{color, size}{Passed to \code{\link[ggplot2:element]{ggplot2::element_line()}}.} +\item{color, linewidth}{Passed to \code{\link[ggplot2:element]{ggplot2::element_line()}}.} } \value{ A \strong{ggplot2} layer or \code{\link[ggplot2:theme]{ggplot2::theme()}} object that can be From 9b40bf7d9c59558f75b9903bc7daee4f3039b389 Mon Sep 17 00:00:00 2001 From: ishaan-arora-1 Date: Tue, 10 Mar 2026 20:33:15 +0530 Subject: [PATCH 2/2] Deprecate grid_lines(size) instead of removing it grid_lines() is exported, so we can't just drop the size parameter without breaking user code. Keep it with a lifecycle deprecation warning pointing to linewidth. Also adds lifecycle as an imported dependency and updates the test to use linewidth. --- DESCRIPTION | 1 + NAMESPACE | 3 +++ R/bayesplot-helpers.R | 13 +++++++++++-- R/bayesplot-package.R | 1 + man/bayesplot-helpers.Rd | 4 +++- tests/testthat/test-convenience-functions.R | 2 +- 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9f47b08bc..6b28a1997 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,6 +34,7 @@ Imports: ggplot2 (>= 3.4.0), ggridges (>= 0.5.5), glue, + lifecycle, posterior, reshape2, rlang (>= 0.3.0), diff --git a/NAMESPACE b/NAMESPACE index b8cf818b5..56bfb0454 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -226,3 +226,6 @@ importFrom(dplyr,top_n) importFrom(dplyr,ungroup) importFrom(dplyr,vars) importFrom(ggplot2,"%+replace%") +importFrom(lifecycle,deprecate_warn) +importFrom(lifecycle,deprecated) +importFrom(lifecycle,is_present) diff --git a/R/bayesplot-helpers.R b/R/bayesplot-helpers.R index 346507a32..f5467946c 100644 --- a/R/bayesplot-helpers.R +++ b/R/bayesplot-helpers.R @@ -447,8 +447,17 @@ plot_bg <- function(on = TRUE, ...) { #' @rdname bayesplot-helpers #' @export #' @param color,linewidth Passed to [ggplot2::element_line()]. -#' -grid_lines <- function(color = "gray50", linewidth = 0.2) { +#' @param size `r lifecycle::badge("deprecated")` Use `linewidth` instead. +#' +grid_lines <- function(color = "gray50", linewidth = 0.2, size = deprecated()) { + if (lifecycle::is_present(size)) { + lifecycle::deprecate_warn( + "1.16.0", + "grid_lines(size)", + "grid_lines(linewidth)" + ) + linewidth <- size + } theme( panel.grid.major = element_line(color = color, linewidth = linewidth), panel.grid.minor = element_line(color = color, linewidth = linewidth * 0.5) diff --git a/R/bayesplot-package.R b/R/bayesplot-package.R index 2727a62ac..db740a9a0 100644 --- a/R/bayesplot-package.R +++ b/R/bayesplot-package.R @@ -5,6 +5,7 @@ #' #' @import ggplot2 stats rlang #' @importFrom dplyr %>% summarise group_by select +#' @importFrom lifecycle deprecated deprecate_warn is_present #' #' @description #' \if{html}{ diff --git a/man/bayesplot-helpers.Rd b/man/bayesplot-helpers.Rd index b668951ea..460511d0b 100644 --- a/man/bayesplot-helpers.Rd +++ b/man/bayesplot-helpers.Rd @@ -63,7 +63,7 @@ panel_bg(on = TRUE, ...) plot_bg(on = TRUE, ...) -grid_lines(color = "gray50", linewidth = 0.2) +grid_lines(color = "gray50", linewidth = 0.2, size = deprecated()) overlay_function(...) } @@ -113,6 +113,8 @@ simply \code{facet_text(FALSE)} to a ggplot object. If \code{on=TRUE} (the defau then \code{...} can be used to customize the appearance of the theme element.} \item{color, linewidth}{Passed to \code{\link[ggplot2:element]{ggplot2::element_line()}}.} + +\item{size}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{linewidth} instead.} } \value{ A \strong{ggplot2} layer or \code{\link[ggplot2:theme]{ggplot2::theme()}} object that can be diff --git a/tests/testthat/test-convenience-functions.R b/tests/testthat/test-convenience-functions.R index 7b197f279..a6f76499b 100644 --- a/tests/testthat/test-convenience-functions.R +++ b/tests/testthat/test-convenience-functions.R @@ -63,7 +63,7 @@ test_that("lbub works", { # plot and facet backgrounds ---------------------------------------------- test_that("grid_lines returns correct theme object", { - thm <- theme_default() + grid_lines(size = 1.5, color = "purple") + thm <- theme_default() + grid_lines(linewidth = 1.5, color = "purple") expect_equal(thm$panel.grid.major, element_line(linewidth = 1.5, color = "purple")) expect_equal(thm$panel.grid.minor, element_line(linewidth = 0.75, color = "purple")) })