Title: | Insert Proper Minus Signs |
---|---|
Description: | Provides convenience functions to replace hyphen-minuses (ASCII 45) with proper minus signs (Unicode character 2212). The true minus matches the plus symbol in width, line thickness, and height above the baseline. It was designed for mathematics, looks better in presentation, and is understood properly by screen readers. |
Authors: | Benjamin E. Wolfe [aut, cre] |
Maintainer: | Benjamin E. Wolfe <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.2.9000 |
Built: | 2024-11-20 03:19:53 UTC |
Source: | https://github.com/benjaminwolfe/signs |
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!
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") )
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") )
x |
Numeric vector. |
... |
Other arguments passed on to |
format |
Any function that takes a numeric vector
and returns a character vector,
such as |
add_plusses |
Logical. Should positive values have plus signs? |
trim_leading_zeros |
Logical. Should |
label_at_zero |
Character. What should be returned
when |
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.
A UTF-8
character vector
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)
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)
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") )
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") )
... |
Other arguments passed on to |
format |
Any function that takes a numeric vector
and returns a character vector,
such as |
add_plusses |
Logical. Should positive values have plus signs? |
trim_leading_zeros |
Logical. Should |
label_at_zero |
Character. What should be returned
when |
See signs
for details.
A function that takes a numeric vector
and returns a UTF-8
character vector
x <- seq(-5, 5) scales::number(x) f1 <- signs_format() f1(x) f2 <- signs_format(accuracy = 1, scale = 1, format = scales::percent) f2(x) f3 <- signs_format(add_plusses = TRUE) f3(x) f4 <- signs_format(add_plusses = TRUE, label_at_zero = "blank") f4(x) f5 <- signs_format(add_plusses = TRUE, label_at_zero = "symbol") f5(x) f6 <- signs_format(accuracy = .1, scale = .1, trim_leading_zeros = TRUE) f6(x)
x <- seq(-5, 5) scales::number(x) f1 <- signs_format() f1(x) f2 <- signs_format(accuracy = 1, scale = 1, format = scales::percent) f2(x) f3 <- signs_format(add_plusses = TRUE) f3(x) f4 <- signs_format(add_plusses = TRUE, label_at_zero = "blank") f4(x) f5 <- signs_format(add_plusses = TRUE, label_at_zero = "symbol") f5(x) f6 <- signs_format(accuracy = .1, scale = .1, trim_leading_zeros = TRUE) f6(x)