Themes allow customization of default values that can be defined in a single place. Using a CascadingTheme allows minimal repetition in defining these values. Normally, a Graphic will be rendered by the Builder using with_theme(), such that a set of defaults is available. Any function that gets called by the Builder or Renderer can use theme() to make a default value configurable.

theme(
  key,
  default = abort(glue::glue("No value for `theme('{key}')`"), "no_theme_key")
)

with_theme(cascading_theme, expr)

Arguments

key

A key

default

A value to return if key is not defined in the current theme

cascading_theme

A CascadingTheme (or something else with a $value() method)

expr

An expression to evaluate with cascading_theme temporarily set as the default theme

Examples

# if there is no theme set, the default value is returned theme("first", "a sensible default value")
#> [1] "a sensible default value"
# with a theme set test_theme <- CascadingTheme$new()$set_values("first" = 1) with_theme(test_theme, 2 * theme("first"))
#> [1] 2