Title: | Insert Proper Minus Signs |
Version: | 0.1.2 |
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. |
URL: | https://benjaminwolfe.github.io/signs |
BugReports: | https://github.com/BenjaminWolfe/signs/issues |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
LazyData: | true |
Imports: | scales, rlang (≥ 0.4.0) |
RoxygenNote: | 7.0.2 |
Suggests: | ggplot2, dplyr, ggrepel, testthat (≥ 2.1.0), knitr, rmarkdown, covr |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2020-01-16 17:57:54 UTC; benjamin |
Author: | Benjamin E. Wolfe |
Maintainer: | Benjamin E. Wolfe <benjamin.e.wolfe@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2020-01-16 18:30:02 UTC |
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 |
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 |
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)
A function factory to add proper minus signs
Description
Returns a function that will format numeric vectors with proper minus signs.
Usage
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 |
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 |
Details
See signs
for details.
Value
A function that takes a numeric vector
and returns a UTF-8
character vector
Examples
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)