theme: Get a value from the current theme

Description Usage Arguments Examples

View source: R/theme.R

Description

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.

Usage

1
2
3
4
5
6
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

1
2
3
4
5
6
# if there is no theme set, the default value is returned
theme("first", "a sensible default value")

# with a theme set
test_theme <- CascadingTheme$new()$set_values("first" = 1)
with_theme(test_theme, 2 * theme("first"))

paleolimbot/ggr6 documentation built on Feb. 5, 2020, 2:17 p.m.