Skip to content

Commit

Permalink
document
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Oct 7, 2024
1 parent 29402b4 commit 0a94bcc
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ Config/testthat/edition: 3
Encoding: UTF-8
LazyLoad: yes
Roxygen: list(markdown = TRUE, r6 = FALSE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export(label_currency)
export(label_date)
export(label_date_short)
export(label_dollar)
export(label_glue)
export(label_log)
export(label_math)
export(label_number)
Expand Down
28 changes: 27 additions & 1 deletion R/label-glue.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@

#' Interpolated labels
#'
#' Use `label_glue()` to perform string interpolation using the \pkg{glue}
#' package. Enclosed expressions will be evaluated as R code.
#'
#' @param pattern A glue string used for formatting. The `x` variable holds the
#' breaks, so that `"{x}"` (default) returns the breaks as-is.
#' @param ... Arguments passed on to [`glue::glue()`].
#' @inheritParams glue::glue
#'
#' @return A labeller function that takes a vector of breaks and returns a
#' character vector of labels.
#' @export
#' @family labels for continuous scales
#' @family labels for discrete scales
#'
#' @examples
#' # Example variables
#' animal <- "penguin"
#' species <- c("Adelie", "Chinstrap", "Emperor", "Gentoo")
#'
#' # Typical use, note that {x} will become the breaks
#' demo_discrete(species, labels = label_glue("The {x}\n{animal}"))
#' # It adapts to the breaks that are present
#' demo_discrete(species[-3], labels = label_glue("The {x}\n{animal}"))
#' # Contrary to directly glueing species + animal, which results in mislabelling!
#' demo_discrete(species[-3], labels = glue::glue("The {species}\n{animal}"))
label_glue <- function(pattern = "{x}", ..., .envir = caller_env()) {
args <- list2(...)
force_all(pattern, .envir)
Expand Down
1 change: 1 addition & 0 deletions man/label_bytes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/label_currency.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions man/label_glue.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/label_number_auto.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/label_number_si.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/label_ordinal.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/label_parse.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/label_percent.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/label_pvalue.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/label_scientific.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/label_wrap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0a94bcc

Please sign in to comment.