Skip to content

Commit

Permalink
document
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Oct 3, 2024
1 parent dbbbb3e commit 714633c
Show file tree
Hide file tree
Showing 21 changed files with 299 additions and 105 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ Config/testthat/edition: 3
Encoding: UTF-8
LazyLoad: yes
Roxygen: list(markdown = TRUE, r6 = FALSE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export(number)
export(number_bytes)
export(number_bytes_format)
export(number_format)
export(number_options)
export(oob_censor)
export(oob_censor_any)
export(oob_discard)
Expand Down
39 changes: 38 additions & 1 deletion R/label-number.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
#' processed so that `prefix = "$"` will yield (e.g.) `-$1` and `($1)`.
#' @param suffix Additional text to display after the number.
#' @param big.mark Character used between every 3 digits to separate thousands.
#' The default (`NULL`) retrieves the setting from the
#' [number options][number_options].
#' @param decimal.mark The character to be used to indicate the numeric
#' decimal point.
#' decimal point. The default (`NULL`) retrieves the setting from the
#' [number options][number_options].
#' @param style_positive A string that determines the style of positive numbers:
#'
#' * `"none"` (the default): no change, e.g. `1`.
Expand All @@ -38,13 +41,19 @@
#' as wide as a number or `+`. Compared to `"none"`, adding a figure space
#' can ensure numbers remain properly aligned when they are left- or
#' right-justified.
#'
#' The default (`NULL`) retrieves the setting from the
#' [number options][number_options].
#' @param style_negative A string that determines the style of negative numbers:
#'
#' * `"hyphen"` (the default): preceded by a standard hypen `-`, e.g. `-1`.
#' * `"minus"`, uses a proper Unicode minus symbol. This is a typographical
#' nicety that ensures `-` aligns with the horizontal bar of the
#' the horizontal bar of `+`.
#' * `"parens"`, wrapped in parentheses, e.g. `(1)`.
#'
#' The default (`NULL`) retrieves the setting from the
#' [number options][number_options].
#' @param scale_cut Named numeric vector that allows you to rescale large
#' (or small) numbers and add a prefix. Built-in helpers include:
#' * `cut_short_scale()`: [10^3, 10^6) = K, [10^6, 10^9) = M, [10^9, 10^12) = B, [10^12, Inf) = T.
Expand Down Expand Up @@ -302,6 +311,34 @@ number <- function(x, accuracy = NULL, scale = 1, prefix = "",
ret
}

#' Number options
#'
#' Control the settings for formatting numbers globally.
#'
#' @inheritParams label_number
#' @param currency.prefix,currency.suffix,currency.decimal.mark,currency.big.mark
#' Settings for [`label_currency()`] passed on without the `currency.`-prefix.
#' @param ordinal.rules Setting for [`label_ordinal()`] passed on without the
#' `ordinal.`-prefix.
#'
#' @return The old options invisibly
#' @export
#'
#' @examples
#' # Default number formatting
#' x <- c(0.1, 1, 1000)
#' label_number()(x)
#'
#' # Now again with new options set
#' number_options(style_positive = "plus", decimal.mark = ",")
#' label_number()(x)
#'
#' # The options are the argument names with a 'scales.'-prefix
#' options("scales.style_positive")
#'
#' # Resetting the options to their defaults
#' number_options()
#' label_number()(x)
number_options <- function(
decimal.mark = ".",
big.mark = " ",
Expand Down
25 changes: 17 additions & 8 deletions man/comma.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions man/dollar_format.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions man/label_bytes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 17 additions & 8 deletions man/label_currency.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions man/label_date.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 17 additions & 8 deletions man/label_number.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions man/label_number_si.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 714633c

Please sign in to comment.