Skip to content

Commit 6df5cd4

Browse files
authored
theme() supports splicing arguments (#5543)
* Move `...` to first argument * `find_args()` uses `list2()` * add test * add news bullet
1 parent 4a3dd71 commit 6df5cd4

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ggplot2 (development version)
22

3+
* `theme()` now supports splicing a list of arguments (#5542).
4+
35
* Contour functions will not fail when `options("OutDec")` is not `.` (@eliocamp, #5555).
46

57
* The `legend.key` theme element is set to inherit from the `panel.background`

R/theme.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@
281281
#' p3 + theme(strip.text.x.top = element_text(colour = "white", face = "bold"))
282282
#' p3 + theme(panel.spacing = unit(1, "lines"))
283283
#' }
284-
theme <- function(line,
284+
theme <- function(...,
285+
line,
285286
rect,
286287
text,
287288
title,
@@ -388,7 +389,6 @@ theme <- function(line,
388389
strip.text.y.right,
389390
strip.switch.pad.grid,
390391
strip.switch.pad.wrap,
391-
...,
392392
complete = FALSE,
393393
validate = TRUE) {
394394
elements <- find_args(..., complete = NULL, validate = NULL)

R/utilities.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ find_args <- function(...) {
320320
vals <- mget(args, envir = env)
321321
vals <- vals[!vapply(vals, is_missing_arg, logical(1))]
322322

323-
modify_list(vals, list(..., `...` = NULL))
323+
modify_list(vals, list2(..., `...` = NULL))
324324
}
325325

326326
# Used in annotations to ensure printed even when no

man/theme.Rd

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-theme.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ test_that("dollar subsetting the theme does no partial matching", {
66
expect_equal(t$foobar, 12)
77
})
88

9+
test_that("theme argument splicing works", {
10+
l <- list(a = 10, b = "c", d = c("foo", "bar"))
11+
test <- theme(!!!l)
12+
ref <- theme(a = 10, b = "c", d = c("foo", "bar"))
13+
expect_equal(test, ref)
14+
})
15+
916
test_that("modifying theme element properties with + operator works", {
1017

1118
# Changing a "leaf node" works

0 commit comments

Comments
 (0)