signs {signs}R Documentation

Add proper minus signs

Description

The true minus sign (Unicode 2212) – neither an em dash, nor an en dash, nor the usual hyphen-minus – is highly underrated. It makes everything look better!

Usage

signs(
  x,
  ...,
  format = getOption("signs.format", scales::number),
  add_plusses = getOption("signs.add.plusses", FALSE),
  trim_leading_zeros = getOption("signs.trim.leading.zeros", FALSE),
  label_at_zero = getOption("signs.label.at.zero", "none")
)

Arguments

x

Numeric vector.

...

Other arguments passed on to format.

format

Any function that takes a numeric vector and returns a character vector, such as scales::number, scales::comma, or scales::percent (all of which are documented at number_format).

add_plusses

Logical. Should positive values have plus signs?

trim_leading_zeros

Logical. Should signs trim leading zeros from values of x between -1 and 1?

label_at_zero

Character. What should be returned when x = 0? Options "none" (no change), "blank" (a zero-length string), or "symbol" (add a plus-minus symbol).

Details

add_plusses, trim_leading_zeros, and label_at_zero are offered for convenience.

The options signs.format, signs.add.plusses, signs.trim.leading.zeros, and signs.label.at.zero are set when the package is loaded to scales::number, FALSE, FALSE, and "none", respectively. If the package is not loaded and the these options are not otherwise set, signs will use those defaults.

label_at_zero is applied after format; that is, if it is "blank" and you've specified an accuracy of 0.1, -0.04 will show as blank.

Value

A UTF-8 character vector

Examples

x <- seq(-5, 5)
scales::number(x)
signs(x)
signs(x, accuracy = 1, scale = 1, format = scales::percent)
signs(x, add_plusses = TRUE)
signs(x, add_plusses = TRUE, label_at_zero = "blank")
signs(x, add_plusses = TRUE, label_at_zero = "symbol")
signs(x, accuracy = .1, scale = .1, trim_leading_zeros = TRUE)

[Package signs version 0.1.2 Index]