tidyverse / ggplot2

An implementation of the Grammar of Graphics in R
https://ggplot2.tidyverse.org
Other
6.45k stars 2.02k forks source link

Preserve theme class #5823

Closed teunbrand closed 5 months ago

teunbrand commented 5 months ago

This PR aims to fix a revdep failure reported in #5822.

Subsetting a theme drops the class:

library(ggplot2)
class(theme())
#> [1] "theme" "gg"
class(theme()[])
#> [1] "list"

Created on 2024-04-03 with reprex v2.1.0

We subsetted the theme in #5743 to drop unknown elements, but an extension (mine, guilty as charged) relied on classed behaviour of theme settings (invoking add_theme() via +). This PR replaced the subsetting operation with assigning NULL to unknown theme settings, preserving the class.