Skip to content

Commit 9125d57

Browse files
committed
Document/export also related functions
1 parent 4724aec commit 9125d57

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ export(geom_vline)
419419
export(get_alt_text)
420420
export(get_element_tree)
421421
export(get_geom_defaults)
422+
export(get_ggplot2_edition)
422423
export(get_guide_data)
423424
export(get_labs)
424425
export(get_last_plot)
@@ -493,6 +494,7 @@ export(layer_grob)
493494
export(layer_scales)
494495
export(layer_sf)
495496
export(lims)
497+
export(local_ggplot2_edition)
496498
export(make_constructor)
497499
export(map_data)
498500
export(margin)
@@ -751,6 +753,7 @@ export(update_stat_defaults)
751753
export(update_theme)
752754
export(vars)
753755
export(waiver)
756+
export(with_ggplot2_edition)
754757
export(wrap_dims)
755758
export(xlab)
756759
export(xlim)

R/utilities-lifecycle.R

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,52 @@
77
#' @param edition An edition. Possible values currently include `"2026"` only.
88
#' Can be `NULL` (default) to unset an edition.
99
#'
10-
#' @returns The previous `edition` value. This function is called for the side
11-
#' effect of setting the edition though.
10+
#' @returns For `set_ggplot2_edition()`, the previous `edition` value and for
11+
#' `local_ggplot2_edition()`: `NULL`. Thesef unction are called for the side
12+
#' effect of setting the edition though. For `with_ggplot2_edition`, the
13+
#' result of the evaluation. For `get_ggplot2_edition()`, the currently
14+
#' active edition.
15+
#'
1216
#' @export
1317
#' @keywords internal
1418
#'
1519
#' @examples
1620
#' # Setting an edition
1721
#' set_ggplot2_edition(2026)
1822
#'
23+
#' # Getting the edition
24+
#' get_ggplot2_edition()
25+
#'
26+
#'
1927
#' # Unsetting an edition
2028
#' set_ggplot2_edition()
29+
#'
30+
#' # Using withr-like scoping
31+
#' with_ggplot2_edition(2026, get_ggplot2_edition())
2132
set_ggplot2_edition <- function(edition = NULL) {
2233
old <- ggplot_global$edition
2334
ggplot_global$edition <- validate_edition(edition)
2435
invisible(old)
2536
}
2637

27-
local_ggplot2_edition <- function(edition, env = parent.frame()) {
38+
#' @export
39+
#' @param env An `environment` to use for scoping.
40+
#' @rdname set_ggplot2_edition
41+
local_ggplot2_edition <- function(edition = NULL, env = parent.frame()) {
2842
old <- set_ggplot2_edition(edition)
2943
withr::defer(set_ggplot2_edition(old), envir = env)
3044
}
3145

32-
with_ggplot2_edition <- function(edition, code) {
46+
#' @export
47+
#' @param code Code to execute in the temporary environment.
48+
#' @rdname set_ggplot2_edition
49+
with_ggplot2_edition <- function(edition = NULL, code) {
3350
local_ggplot2_edition(edition)
3451
code
3552
}
3653

54+
#' @export
55+
#' @rdname set_ggplot2_edition
3756
get_ggplot2_edition <- function() {
3857
ggplot_global$edition[[1]]
3958
}

man/set_ggplot2_edition.Rd

Lines changed: 25 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)