Returns a function that will format numeric vectors with proper minus signs.

signs_format(
  ...,
  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

...

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).

Value

A function that takes a numeric vector and returns a UTF-8 character vector

Details

See signs for details.

Examples

x <- seq(-5, 5) scales::number(x)
#> [1] "-5.0" "-4.0" "-3.0" "-2.0" "-1.0" "0.0" "1.0" "2.0" "3.0" "4.0" #> [11] "5.0"
f1 <- signs_format() f1(x)
#> [1] "−5.0" "−4.0" "−3.0" "−2.0" "−1.0" "0.0" "1.0" "2.0" "3.0" "4.0" #> [11] "5.0"
f2 <- signs_format(accuracy = 1, scale = 1, format = scales::percent) f2(x)
#> [1] "−5%" "−4%" "−3%" "−2%" "−1%" "0%" "1%" "2%" "3%" "4%" "5%"
f3 <- signs_format(add_plusses = TRUE) f3(x)
#> [1] "−5.0" "−4.0" "−3.0" "−2.0" "−1.0" "0.0" "+1.0" "+2.0" "+3.0" "+4.0" #> [11] "+5.0"
f4 <- signs_format(add_plusses = TRUE, label_at_zero = "blank") f4(x)
#> [1] "−5.0" "−4.0" "−3.0" "−2.0" "−1.0" "" "+1.0" "+2.0" "+3.0" "+4.0" #> [11] "+5.0"
f5 <- signs_format(add_plusses = TRUE, label_at_zero = "symbol") f5(x)
#> [1] "−5.0" "−4.0" "−3.0" "−2.0" "−1.0" "±0.0" "+1.0" "+2.0" "+3.0" "+4.0" #> [11] "+5.0"
f6 <- signs_format(accuracy = .1, scale = .1, trim_leading_zeros = TRUE) f6(x)
#> [1] "−.5" "−.4" "−.3" "−.2" "−.1" ".0" ".1" ".2" ".3" ".4" ".5"