Skip to content

Commit 360c975

Browse files
committed
don't rely on element$prop
1 parent 3bc0d63 commit 360c975

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

R/save.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ ggsave <- function(filename, plot = get_last_plot(),
103103
limitsize = limitsize, dpi = dpi)
104104

105105
if (is_null(bg)) {
106-
bg <- calc_element("plot.background", plot_theme(plot))$fill %||% "transparent"
106+
bg <- calc_element("plot.background", plot_theme(plot))
107+
bg <- if (S7::prop_exists(bg, "fill")) bg@fill else NULL
108+
bg <- bg %||% "transparent"
107109
}
108110
old_dev <- grDevices::dev.cur()
109111
dev(filename = filename, width = dim[1], height = dim[2], bg = bg, ...)

R/theme.R

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -779,15 +779,22 @@ calc_element <- function(element, theme, verbose = FALSE, skip_blank = FALSE,
779779

780780
# Calculate the parent objects' inheritance
781781
if (verbose) cli::cli_inform("{pnames}")
782+
783+
# once we've started skipping blanks, we continue doing so until the end of the
784+
# recursion; we initiate skipping blanks if we encounter an element that
785+
# doesn't inherit blank.
786+
skip_blank <- skip_blank ||
787+
(!is.null(el_out) &&
788+
!isTRUE(S7::S7_inherits(el_out) &&
789+
S7::prop_exists(el_out, "inherit.blank") &&
790+
el_out@inherit.blank))
791+
782792
parents <- lapply(
783793
pnames,
784794
calc_element,
785795
theme,
786796
verbose = verbose,
787-
# once we've started skipping blanks, we continue doing so until the end of the
788-
# recursion; we initiate skipping blanks if we encounter an element that
789-
# doesn't inherit blank.
790-
skip_blank = skip_blank || (!is.null(el_out) && !isTRUE(el_out$inherit.blank)),
797+
skip_blank = skip_blank,
791798
call = call
792799
)
793800

tests/testthat/test-theme.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ test_that("all elements in complete themes have inherit.blank=TRUE", {
346346
inherit_blanks <- function(theme) {
347347
all(vapply(theme, function(el) {
348348
if (inherits(el, "element") && !S7::S7_inherits(el, element_blank)) {
349-
el$inherit.blank
349+
el@inherit.blank
350350
} else {
351351
TRUE
352352
}

0 commit comments

Comments
 (0)