From daed2b0cdc68c76d1d416c3b1d5b2a55a92834ed Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 28 Nov 2023 16:20:46 +0100 Subject: [PATCH 1/4] Move `...` to first argument --- R/theme.R | 4 ++-- man/theme.Rd | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R/theme.R b/R/theme.R index 1774a23e08..3184e2b984 100644 --- a/R/theme.R +++ b/R/theme.R @@ -281,7 +281,8 @@ #' p3 + theme(strip.text.x.top = element_text(colour = "white", face = "bold")) #' p3 + theme(panel.spacing = unit(1, "lines")) #' } -theme <- function(line, +theme <- function(..., + line, rect, text, title, @@ -388,7 +389,6 @@ theme <- function(line, strip.text.y.right, strip.switch.pad.grid, strip.switch.pad.wrap, - ..., complete = FALSE, validate = TRUE) { elements <- find_args(..., complete = NULL, validate = NULL) diff --git a/man/theme.Rd b/man/theme.Rd index 7672d42c5a..4c91c5fe85 100644 --- a/man/theme.Rd +++ b/man/theme.Rd @@ -5,6 +5,7 @@ \title{Modify components of a theme} \usage{ theme( + ..., line, rect, text, @@ -112,12 +113,14 @@ theme( strip.text.y.right, strip.switch.pad.grid, strip.switch.pad.wrap, - ..., complete = FALSE, validate = TRUE ) } \arguments{ +\item{...}{additional element specifications not part of base ggplot2. In general, +these should also be defined in the \verb{element tree} argument.} + \item{line}{all line elements (\code{\link[=element_line]{element_line()}})} \item{rect}{all rectangular elements (\code{\link[=element_rect]{element_rect()}})} @@ -298,9 +301,6 @@ switched (\code{unit})} \item{strip.switch.pad.wrap}{space between strips and axes when strips are switched (\code{unit})} -\item{...}{additional element specifications not part of base ggplot2. In general, -these should also be defined in the \verb{element tree} argument.} - \item{complete}{set this to \code{TRUE} if this is a complete theme, such as the one returned by \code{\link[=theme_grey]{theme_grey()}}. Complete themes behave differently when added to a ggplot object. Also, when setting From 2928cdec8a492986b5a52efd7107b9e8b84d1745 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 28 Nov 2023 16:21:10 +0100 Subject: [PATCH 2/4] `find_args()` uses `list2()` --- R/utilities.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utilities.R b/R/utilities.R index 1efbc121ff..5aad65e2cf 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -320,7 +320,7 @@ find_args <- function(...) { vals <- mget(args, envir = env) vals <- vals[!vapply(vals, is_missing_arg, logical(1))] - modify_list(vals, list(..., `...` = NULL)) + modify_list(vals, list2(..., `...` = NULL)) } # Used in annotations to ensure printed even when no From 4e7be5d5dd3b29d22518ce0aaa063d35b942e959 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 28 Nov 2023 16:24:23 +0100 Subject: [PATCH 3/4] add test --- tests/testthat/test-theme.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/testthat/test-theme.R b/tests/testthat/test-theme.R index ab54bf9764..53feb08832 100644 --- a/tests/testthat/test-theme.R +++ b/tests/testthat/test-theme.R @@ -6,6 +6,13 @@ test_that("dollar subsetting the theme does no partial matching", { expect_equal(t$foobar, 12) }) +test_that("theme argument splicing works", { + l <- list(a = 10, b = "c", d = c("foo", "bar")) + test <- theme(!!!l) + ref <- theme(a = 10, b = "c", d = c("foo", "bar")) + expect_equal(test, ref) +}) + test_that("modifying theme element properties with + operator works", { # Changing a "leaf node" works From b487982f6ac10fcc57e91301077f3954d2846e9f Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 28 Nov 2023 16:25:54 +0100 Subject: [PATCH 4/4] add news bullet --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 4596436f9a..b0cf034db7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # ggplot2 (development version) +* `theme()` now supports splicing a list of arguments (#5542). + * Lines where `linewidth = NA` are now dropped in `geom_sf()` (#5204). * New `guide_axis_logticks()` can be used to draw logarithmic tick marks as