Skip to content

theme() supports splicing arguments #5543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ggplot2 (development version)

* `theme()` now supports splicing a list of arguments (#5542).

* Contour functions will not fail when `options("OutDec")` is not `.` (@eliocamp, #5555).

* The `legend.key` theme element is set to inherit from the `panel.background`
Expand Down
4 changes: 2 additions & 2 deletions R/theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions man/theme.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/testthat/test-theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down