lbl_glue {santoku}R Documentation

Label chopped intervals using the glue package

Description

Use "{l}" and "{r}" to show the left and right endpoints of the intervals.

Usage

lbl_glue(
  label,
  fmt = NULL,
  single = NULL,
  first = NULL,
  last = NULL,
  raw = FALSE,
  ...
)

Arguments

label

A glue string passed to glue::glue().

fmt

String, list or function. A format for break endpoints.

single

Glue string: label for singleton intervals. See lbl_glue() for details.

first

Glue string: override label for the first category. Write e.g. first = "<{r}" to create a label like "<18". See lbl_glue() for details.

last

String: override label for the last category. Write e.g. last = ">{l}" to create a label like ">65". See lbl_glue() for details.

raw

[Deprecated]. Use the raw argument to chop() instead.

...

Further arguments passed to glue::glue().

Details

The following variables are available in the glue string:

Endpoints will be formatted by fmt before being passed to glue().

Value

A function that creates a vector of labels.

Formatting endpoints

If fmt is not NULL then it is used to format the endpoints.

See Also

Other labelling functions: lbl_dash(), lbl_discrete(), lbl_endpoints(), lbl_intervals(), lbl_manual(), lbl_midpoints(), lbl_seq()

Examples

tab(1:10, c(1, 3, 3, 7),
    labels = lbl_glue("{l} to {r}", single = "Exactly {l}"))

tab(1:10 * 1000, c(1, 3, 5, 7) * 1000,
    labels = lbl_glue("{l}-{r}",
                      fmt = function(x) prettyNum(x, big.mark=',')))

# reproducing lbl_intervals():
interval_left <- "{ifelse(l_closed, '[', '(')}"
interval_right <- "{ifelse(r_closed, ']', ')')}"
glue_string <- paste0(interval_left, "{l}", ", ", "{r}", interval_right)
tab(1:10, c(1, 3, 3, 7), labels = lbl_glue(glue_string, single = "{{{l}}}"))


[Package santoku version 1.0.0 Index]