From b9f6ebccf1fc0036a35aa30618919590a50bc99c Mon Sep 17 00:00:00 2001 From: Bjarke Hautop Date: Sun, 4 Jan 2026 19:28:26 +0100 Subject: [PATCH 1/2] Fix all size warnings calls to ggplot2 (deprecated at 3.4.0). Deprecated arg size and added linewidth as new preferred arg where it made sense. --- DESCRIPTION | 1 + NAMESPACE | 1 + R/mcmc-traces.R | 4 ++-- R/ppc-censoring.R | 37 ++++++++++++++++++++++------- R/ppc-discrete.R | 2 +- R/ppd-intervals.R | 2 +- man/PPC-censoring.Rd | 10 +++++--- tests/testthat/test-ppc-censoring.R | 14 +++++------ 8 files changed, 49 insertions(+), 22 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9f47b08b..6b28a199 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 4823d8df..2ebc9597 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -224,3 +224,4 @@ importFrom(dplyr,top_n) importFrom(dplyr,ungroup) importFrom(dplyr,vars) importFrom(ggplot2,"%+replace%") +importFrom(lifecycle,deprecated) diff --git a/R/mcmc-traces.R b/R/mcmc-traces.R index 571a6ce2..57449883 100644 --- a/R/mcmc-traces.R +++ b/R/mcmc-traces.R @@ -337,7 +337,7 @@ mcmc_rank_overlay <- function(x, geom_hline( yintercept = (right_edge / n_bins) / n_chains, color = get_color("dark_highlight"), - size = 1, + linewidth = 1, linetype = "dashed" ) } else { @@ -417,7 +417,7 @@ mcmc_rank_hist <- function(x, geom_hline( yintercept = (right_edge / n_bins) / n_chains, color = get_color("dark_highlight"), - size = .5, + linewidth = .5, linetype = "dashed" ) } else { diff --git a/R/ppc-censoring.R b/R/ppc-censoring.R index 39a22ce0..cfe10fed 100644 --- a/R/ppc-censoring.R +++ b/R/ppc-censoring.R @@ -15,8 +15,9 @@ #' @family PPCs #' #' @template args-y-yrep -#' @param size,alpha Passed to the appropriate geom to control the appearance of +#' @param linewidth,alpha Passed to the appropriate geom to control the appearance of #' the `yrep` distributions. +#' @param size `r lifecycle::badge("deprecated")` Please use `linewidth` instead of `size`. #' @param ... Currently only used internally. #' #' @template return-ggplot @@ -96,7 +97,7 @@ NULL #' posterior predictive draws may not be shown by default because of the #' controlled extrapolation. To display all posterior predictive draws, set #' `extrapolation_factor = Inf`. -#' +#' @importFrom lifecycle deprecated ppc_km_overlay <- function( y, yrep, @@ -104,9 +105,19 @@ ppc_km_overlay <- function( status_y, left_truncation_y = NULL, extrapolation_factor = 1.2, - size = 0.25, + linewidth = 0.25, + size = deprecated(), alpha = 0.7 ) { + if (lifecycle::is_present(size)) { + lifecycle::deprecate_warn( + "1.16.0", + "ppc_km_overlay(size)", + details = "Please use `linewidth` instead of `size`." + ) + linewidth <- size + } + check_ignored_arguments(..., ok_args = "add_group") add_group <- list(...)$add_group @@ -173,7 +184,7 @@ ppc_km_overlay <- function( } fsf$is_y_color <- as.factor(sub("\\[rep\\] \\(.*$", "rep", sub("^italic\\(y\\)", "y", fsf$strata))) - fsf$is_y_size <- ifelse(fsf$is_y_color == "yrep", size, 1) + fsf$is_y_linewidth <- ifelse(fsf$is_y_color == "yrep", linewidth, 1) fsf$is_y_alpha <- ifelse(fsf$is_y_color == "yrep", alpha, 1) max_time_y <- max(y, na.rm = TRUE) @@ -189,7 +200,7 @@ ppc_km_overlay <- function( y = .data$surv, color = .data$is_y_color, group = .data$strata, - size = .data$is_y_size, + linewidth = .data$is_y_linewidth, alpha = .data$is_y_alpha)) + geom_step() + hline_at( @@ -204,7 +215,7 @@ ppc_km_overlay <- function( linetype = 2, color = get_color("dh") ) + - scale_size_identity() + + scale_linewidth_identity() + scale_alpha_identity() + scale_color_ppc() + scale_y_continuous(breaks = c(0, 0.5, 1)) + @@ -218,6 +229,7 @@ ppc_km_overlay <- function( #' @export #' @rdname PPC-censoring #' @template args-group +#' @importFrom lifecycle deprecated ppc_km_overlay_grouped <- function( y, yrep, @@ -226,9 +238,18 @@ ppc_km_overlay_grouped <- function( status_y, left_truncation_y = NULL, extrapolation_factor = 1.2, - size = 0.25, + linewidth = 0.25, + size = deprecated(), alpha = 0.7 ) { + if (lifecycle::is_present(size)) { + lifecycle::deprecate_warn( + "1.16.0", + "ppc_km_overlay_grouped(size)", + details = "Please use `linewidth` instead of `size`." + ) + linewidth <- size + } check_ignored_arguments(...) p_overlay <- ppc_km_overlay( @@ -238,7 +259,7 @@ ppc_km_overlay_grouped <- function( ..., status_y = status_y, left_truncation_y = left_truncation_y, - size = size, + linewidth = linewidth, alpha = alpha, extrapolation_factor = extrapolation_factor ) diff --git a/R/ppc-discrete.R b/R/ppc-discrete.R index 09bec1f8..c346247f 100644 --- a/R/ppc-discrete.R +++ b/R/ppc-discrete.R @@ -359,7 +359,7 @@ ppc_rootogram <- function(y, if (style == "standing") { graph <- graph + dont_expand_y_axis() } else { - graph <- graph + hline_0(size = 0.4) + graph <- graph + hline_0(linewidth = 0.4) } } diff --git a/R/ppd-intervals.R b/R/ppd-intervals.R index 096e5287..63184072 100644 --- a/R/ppd-intervals.R +++ b/R/ppd-intervals.R @@ -162,7 +162,7 @@ ppd_ribbon <- linewidth = 0.2 * size, alpha = 1 ) + - geom_ribbon(size = 0.5 * size) + + geom_ribbon(linewidth = 0.5 * size) + geom_line( mapping = aes(y = .data$m), color = get_color("d"), diff --git a/man/PPC-censoring.Rd b/man/PPC-censoring.Rd index ddf011b4..f6dcce29 100644 --- a/man/PPC-censoring.Rd +++ b/man/PPC-censoring.Rd @@ -13,7 +13,8 @@ ppc_km_overlay( status_y, left_truncation_y = NULL, extrapolation_factor = 1.2, - size = 0.25, + linewidth = 0.25, + size = deprecated(), alpha = 0.7 ) @@ -25,7 +26,8 @@ ppc_km_overlay_grouped( status_y, left_truncation_y = NULL, extrapolation_factor = 1.2, - size = 0.25, + linewidth = 0.25, + size = deprecated(), alpha = 0.7 ) } @@ -58,9 +60,11 @@ posterior predictive draws may not be shown by default because of the controlled extrapolation. To display all posterior predictive draws, set \code{extrapolation_factor = Inf}.} -\item{size, alpha}{Passed to the appropriate geom to control the appearance of +\item{linewidth, alpha}{Passed to the appropriate geom to control the appearance of the \code{yrep} distributions.} +\item{size}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Please use \code{linewidth} instead of \code{size}.} + \item{group}{A grouping variable of the same length as \code{y}. Will be coerced to \link[base:factor]{factor} if not already a factor. Each value in \code{group} is interpreted as the group level pertaining diff --git a/tests/testthat/test-ppc-censoring.R b/tests/testthat/test-ppc-censoring.R index 2224df7b..be235587 100644 --- a/tests/testthat/test-ppc-censoring.R +++ b/tests/testthat/test-ppc-censoring.R @@ -2,8 +2,8 @@ source(test_path("data-for-ppc-tests.R")) test_that("ppc_km_overlay returns a ggplot object", { skip_if_not_installed("ggfortify") - expect_gg(ppc_km_overlay(y, yrep, status_y = status_y, left_truncation_y = left_truncation_y, size = 0.5, alpha = 0.2, extrapolation_factor = Inf)) - expect_gg(ppc_km_overlay(y, yrep, status_y = status_y, left_truncation_y = left_truncation_y, size = 0.5, alpha = 0.2, extrapolation_factor = 1)) + expect_gg(ppc_km_overlay(y, yrep, status_y = status_y, left_truncation_y = left_truncation_y, linewidth = 0.5, alpha = 0.2, extrapolation_factor = Inf)) + expect_gg(ppc_km_overlay(y, yrep, status_y = status_y, left_truncation_y = left_truncation_y, linewidth = 0.5, alpha = 0.2, extrapolation_factor = 1)) expect_gg(ppc_km_overlay(y2, yrep2, status_y = status_y2)) }) @@ -12,15 +12,15 @@ test_that("ppc_km_overlay_grouped returns a ggplot object", { expect_gg(ppc_km_overlay_grouped(y, yrep, group, status_y = status_y, left_truncation_y = left_truncation_y, - size = 0.5, alpha = 0.2)) + linewidth = 0.5, alpha = 0.2)) expect_gg(ppc_km_overlay_grouped(y, yrep, as.numeric(group), status_y = status_y, left_truncation_y = left_truncation_y, - size = 0.5, alpha = 0.2)) + linewidth = 0.5, alpha = 0.2)) expect_gg(ppc_km_overlay_grouped(y, yrep, as.integer(group), status_y = status_y, left_truncation_y = left_truncation_y, - size = 0.5, alpha = 0.2)) + linewidth = 0.5, alpha = 0.2)) expect_gg(ppc_km_overlay_grouped(y2, yrep2, group2, status_y = status_y2)) @@ -89,7 +89,7 @@ test_that("ppc_km_overlay renders correctly", { vdiff_y2, vdiff_yrep2, status_y = vdiff_status_y2, - size = 2, + linewidth = 2, alpha = .2) vdiffr::expect_doppelganger("ppc_km_overlay (size, alpha)", p_custom) @@ -138,7 +138,7 @@ test_that("ppc_km_overlay_grouped renders correctly", { vdiff_yrep2, vdiff_group2, status_y = vdiff_status_y2, - size = 2, + linewidth = 2, alpha = .2 ) From e2b62b98e7a39427f08e33984b6ae5ae9d1fa5f4 Mon Sep 17 00:00:00 2001 From: Bjarke Hautop Date: Wed, 7 Jan 2026 19:06:11 +0100 Subject: [PATCH 2/2] Remove deprecations warnings to size --- DESCRIPTION | 1 - NAMESPACE | 1 - R/ppc-censoring.R | 32 +++++------------------------ man/PPC-censoring.Rd | 10 +++------ tests/testthat/test-ppc-censoring.R | 14 ++++++------- 5 files changed, 15 insertions(+), 43 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6b28a199..9f47b08b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,7 +34,6 @@ Imports: ggplot2 (>= 3.4.0), ggridges (>= 0.5.5), glue, - lifecycle, posterior, reshape2, rlang (>= 0.3.0), diff --git a/NAMESPACE b/NAMESPACE index 2ebc9597..4823d8df 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -224,4 +224,3 @@ importFrom(dplyr,top_n) importFrom(dplyr,ungroup) importFrom(dplyr,vars) importFrom(ggplot2,"%+replace%") -importFrom(lifecycle,deprecated) diff --git a/R/ppc-censoring.R b/R/ppc-censoring.R index cfe10fed..e41cbae9 100644 --- a/R/ppc-censoring.R +++ b/R/ppc-censoring.R @@ -15,9 +15,8 @@ #' @family PPCs #' #' @template args-y-yrep -#' @param linewidth,alpha Passed to the appropriate geom to control the appearance of +#' @param size,alpha Passed to the appropriate geom to control the appearance of #' the `yrep` distributions. -#' @param size `r lifecycle::badge("deprecated")` Please use `linewidth` instead of `size`. #' @param ... Currently only used internally. #' #' @template return-ggplot @@ -97,7 +96,6 @@ NULL #' posterior predictive draws may not be shown by default because of the #' controlled extrapolation. To display all posterior predictive draws, set #' `extrapolation_factor = Inf`. -#' @importFrom lifecycle deprecated ppc_km_overlay <- function( y, yrep, @@ -105,19 +103,9 @@ ppc_km_overlay <- function( status_y, left_truncation_y = NULL, extrapolation_factor = 1.2, - linewidth = 0.25, - size = deprecated(), + size = 0.25, alpha = 0.7 ) { - if (lifecycle::is_present(size)) { - lifecycle::deprecate_warn( - "1.16.0", - "ppc_km_overlay(size)", - details = "Please use `linewidth` instead of `size`." - ) - linewidth <- size - } - check_ignored_arguments(..., ok_args = "add_group") add_group <- list(...)$add_group @@ -184,7 +172,7 @@ ppc_km_overlay <- function( } fsf$is_y_color <- as.factor(sub("\\[rep\\] \\(.*$", "rep", sub("^italic\\(y\\)", "y", fsf$strata))) - fsf$is_y_linewidth <- ifelse(fsf$is_y_color == "yrep", linewidth, 1) + fsf$is_y_linewidth <- ifelse(fsf$is_y_color == "yrep", size, 1) fsf$is_y_alpha <- ifelse(fsf$is_y_color == "yrep", alpha, 1) max_time_y <- max(y, na.rm = TRUE) @@ -229,7 +217,6 @@ ppc_km_overlay <- function( #' @export #' @rdname PPC-censoring #' @template args-group -#' @importFrom lifecycle deprecated ppc_km_overlay_grouped <- function( y, yrep, @@ -238,18 +225,9 @@ ppc_km_overlay_grouped <- function( status_y, left_truncation_y = NULL, extrapolation_factor = 1.2, - linewidth = 0.25, - size = deprecated(), + size = 0.25, alpha = 0.7 ) { - if (lifecycle::is_present(size)) { - lifecycle::deprecate_warn( - "1.16.0", - "ppc_km_overlay_grouped(size)", - details = "Please use `linewidth` instead of `size`." - ) - linewidth <- size - } check_ignored_arguments(...) p_overlay <- ppc_km_overlay( @@ -259,7 +237,7 @@ ppc_km_overlay_grouped <- function( ..., status_y = status_y, left_truncation_y = left_truncation_y, - linewidth = linewidth, + size = size, alpha = alpha, extrapolation_factor = extrapolation_factor ) diff --git a/man/PPC-censoring.Rd b/man/PPC-censoring.Rd index f6dcce29..ddf011b4 100644 --- a/man/PPC-censoring.Rd +++ b/man/PPC-censoring.Rd @@ -13,8 +13,7 @@ ppc_km_overlay( status_y, left_truncation_y = NULL, extrapolation_factor = 1.2, - linewidth = 0.25, - size = deprecated(), + size = 0.25, alpha = 0.7 ) @@ -26,8 +25,7 @@ ppc_km_overlay_grouped( status_y, left_truncation_y = NULL, extrapolation_factor = 1.2, - linewidth = 0.25, - size = deprecated(), + size = 0.25, alpha = 0.7 ) } @@ -60,11 +58,9 @@ posterior predictive draws may not be shown by default because of the controlled extrapolation. To display all posterior predictive draws, set \code{extrapolation_factor = Inf}.} -\item{linewidth, alpha}{Passed to the appropriate geom to control the appearance of +\item{size, alpha}{Passed to the appropriate geom to control the appearance of the \code{yrep} distributions.} -\item{size}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Please use \code{linewidth} instead of \code{size}.} - \item{group}{A grouping variable of the same length as \code{y}. Will be coerced to \link[base:factor]{factor} if not already a factor. Each value in \code{group} is interpreted as the group level pertaining diff --git a/tests/testthat/test-ppc-censoring.R b/tests/testthat/test-ppc-censoring.R index be235587..2224df7b 100644 --- a/tests/testthat/test-ppc-censoring.R +++ b/tests/testthat/test-ppc-censoring.R @@ -2,8 +2,8 @@ source(test_path("data-for-ppc-tests.R")) test_that("ppc_km_overlay returns a ggplot object", { skip_if_not_installed("ggfortify") - expect_gg(ppc_km_overlay(y, yrep, status_y = status_y, left_truncation_y = left_truncation_y, linewidth = 0.5, alpha = 0.2, extrapolation_factor = Inf)) - expect_gg(ppc_km_overlay(y, yrep, status_y = status_y, left_truncation_y = left_truncation_y, linewidth = 0.5, alpha = 0.2, extrapolation_factor = 1)) + expect_gg(ppc_km_overlay(y, yrep, status_y = status_y, left_truncation_y = left_truncation_y, size = 0.5, alpha = 0.2, extrapolation_factor = Inf)) + expect_gg(ppc_km_overlay(y, yrep, status_y = status_y, left_truncation_y = left_truncation_y, size = 0.5, alpha = 0.2, extrapolation_factor = 1)) expect_gg(ppc_km_overlay(y2, yrep2, status_y = status_y2)) }) @@ -12,15 +12,15 @@ test_that("ppc_km_overlay_grouped returns a ggplot object", { expect_gg(ppc_km_overlay_grouped(y, yrep, group, status_y = status_y, left_truncation_y = left_truncation_y, - linewidth = 0.5, alpha = 0.2)) + size = 0.5, alpha = 0.2)) expect_gg(ppc_km_overlay_grouped(y, yrep, as.numeric(group), status_y = status_y, left_truncation_y = left_truncation_y, - linewidth = 0.5, alpha = 0.2)) + size = 0.5, alpha = 0.2)) expect_gg(ppc_km_overlay_grouped(y, yrep, as.integer(group), status_y = status_y, left_truncation_y = left_truncation_y, - linewidth = 0.5, alpha = 0.2)) + size = 0.5, alpha = 0.2)) expect_gg(ppc_km_overlay_grouped(y2, yrep2, group2, status_y = status_y2)) @@ -89,7 +89,7 @@ test_that("ppc_km_overlay renders correctly", { vdiff_y2, vdiff_yrep2, status_y = vdiff_status_y2, - linewidth = 2, + size = 2, alpha = .2) vdiffr::expect_doppelganger("ppc_km_overlay (size, alpha)", p_custom) @@ -138,7 +138,7 @@ test_that("ppc_km_overlay_grouped renders correctly", { vdiff_yrep2, vdiff_group2, status_y = vdiff_status_y2, - linewidth = 2, + size = 2, alpha = .2 )