From 714633c576fe548343207d8ce5dec0721f75f616 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Thu, 3 Oct 2024 13:39:27 +0200 Subject: [PATCH] document --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/label-number.R | 39 +++++++++++++++++++- man/comma.Rd | 25 +++++++++---- man/dollar_format.Rd | 15 +++++--- man/label_bytes.Rd | 17 +++++++-- man/label_currency.Rd | 25 +++++++++---- man/label_date.Rd | 17 +++++++-- man/label_number.Rd | 25 +++++++++---- man/label_number_si.Rd | 17 +++++++-- man/label_ordinal.Rd | 25 +++++++------ man/label_percent.Rd | 21 ++++++++--- man/label_pvalue.Rd | 5 ++- man/label_scientific.Rd | 5 ++- man/number.Rd | 25 +++++++++---- man/number_options.Rd | 79 ++++++++++++++++++++++++++++++++++++++++ man/ordinal_format.Rd | 21 +++-------- man/percent_format.Rd | 15 +++++--- man/pvalue_format.Rd | 7 ++-- man/scientific_format.Rd | 7 ++-- man/unit_format.Rd | 11 ++++-- 21 files changed, 299 insertions(+), 105 deletions(-) create mode 100644 man/number_options.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 38d99259..0ee8fe58 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 diff --git a/NAMESPACE b/NAMESPACE index 323e34ba..a3ce0f39 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/label-number.R b/R/label-number.R index 95591a21..36e82946 100644 --- a/R/label-number.R +++ b/R/label-number.R @@ -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`. @@ -38,6 +41,9 @@ #' 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`. @@ -45,6 +51,9 @@ #' 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. @@ -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 = " ", diff --git a/man/comma.Rd b/man/comma.Rd index 38f9b7f9..bb03854a 100644 --- a/man/comma.Rd +++ b/man/comma.Rd @@ -24,10 +24,10 @@ number_format( scale = 1, prefix = "", suffix = "", - big.mark = " ", - decimal.mark = ".", - style_positive = c("none", "plus", "space"), - style_negative = c("hyphen", "minus", "parens"), + big.mark = NULL, + decimal.mark = NULL, + style_positive = NULL, + style_negative = NULL, scale_cut = NULL, trim = TRUE, ... @@ -65,10 +65,13 @@ processed so that \code{prefix = "$"} will yield (e.g.) \verb{-$1} and \verb{($1 \item{suffix}{Additional text to display after the number.} -\item{big.mark}{Character used between every 3 digits to separate thousands.} +\item{big.mark}{Character used between every 3 digits to separate thousands. +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{decimal.mark}{The character to be used to indicate the numeric -decimal point.} +decimal point. The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{trim}{Logical, if \code{FALSE}, values are right-justified to a common width (see \code{\link[base:format]{base::format()}}).} @@ -85,7 +88,10 @@ width (see \code{\link[base:format]{base::format()}}).} as wide as a number or \code{+}. Compared to \code{"none"}, adding a figure space can ensure numbers remain properly aligned when they are left- or right-justified. -}} +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{style_negative}{A string that determines the style of negative numbers: \itemize{ @@ -94,7 +100,10 @@ right-justified. nicety that ensures \code{-} aligns with the horizontal bar of the the horizontal bar of \code{+}. \item \code{"parens"}, wrapped in parentheses, e.g. \code{(1)}. -}} +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{scale_cut}{Named numeric vector that allows you to rescale large (or small) numbers and add a prefix. Built-in helpers include: diff --git a/man/dollar_format.Rd b/man/dollar_format.Rd index fc65b2df..0791f2c6 100644 --- a/man/dollar_format.Rd +++ b/man/dollar_format.Rd @@ -23,10 +23,10 @@ dollar( x, accuracy = NULL, scale = 1, - prefix = "$", - suffix = "", - big.mark = ",", - decimal.mark = ".", + prefix = NULL, + suffix = NULL, + big.mark = NULL, + decimal.mark = NULL, trim = TRUE, largest_with_cents = 1e+05, negative_parens = deprecated(), @@ -55,10 +55,13 @@ large.} \item{prefix, suffix}{Symbols to display before and after value.} -\item{big.mark}{Character used between every 3 digits to separate thousands.} +\item{big.mark}{Character used between every 3 digits to separate thousands. +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{decimal.mark}{The character to be used to indicate the numeric -decimal point.} +decimal point. The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{trim}{Logical, if \code{FALSE}, values are right-justified to a common width (see \code{\link[base:format]{base::format()}}).} diff --git a/man/label_bytes.Rd b/man/label_bytes.Rd index 02054433..266649bc 100644 --- a/man/label_bytes.Rd +++ b/man/label_bytes.Rd @@ -35,9 +35,12 @@ large.} applied to absolute value before \code{style_positive} and \code{style_negative} are processed so that \code{prefix = "$"} will yield (e.g.) \verb{-$1} and \verb{($1)}.} \item{\code{suffix}}{Additional text to display after the number.} - \item{\code{big.mark}}{Character used between every 3 digits to separate thousands.} + \item{\code{big.mark}}{Character used between every 3 digits to separate thousands. +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{\code{decimal.mark}}{The character to be used to indicate the numeric -decimal point.} +decimal point. The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{\code{style_positive}}{A string that determines the style of positive numbers: \itemize{ \item \code{"none"} (the default): no change, e.g. \code{1}. @@ -46,7 +49,10 @@ decimal point.} as wide as a number or \code{+}. Compared to \code{"none"}, adding a figure space can ensure numbers remain properly aligned when they are left- or right-justified. -}} +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{\code{style_negative}}{A string that determines the style of negative numbers: \itemize{ \item \code{"hyphen"} (the default): preceded by a standard hypen \code{-}, e.g. \code{-1}. @@ -54,7 +60,10 @@ right-justified. nicety that ensures \code{-} aligns with the horizontal bar of the the horizontal bar of \code{+}. \item \code{"parens"}, wrapped in parentheses, e.g. \code{(1)}. -}} +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{\code{scale_cut}}{Named numeric vector that allows you to rescale large (or small) numbers and add a prefix. Built-in helpers include: \itemize{ diff --git a/man/label_currency.Rd b/man/label_currency.Rd index a29feb17..c0118d92 100644 --- a/man/label_currency.Rd +++ b/man/label_currency.Rd @@ -7,10 +7,10 @@ label_currency( accuracy = NULL, scale = 1, - prefix = "$", - suffix = "", - big.mark = ",", - decimal.mark = ".", + prefix = NULL, + suffix = NULL, + big.mark = NULL, + decimal.mark = NULL, trim = TRUE, largest_with_fractional = 1e+05, ... @@ -29,10 +29,13 @@ large.} \item{prefix, suffix}{Symbols to display before and after value.} -\item{big.mark}{Character used between every 3 digits to separate thousands.} +\item{big.mark}{Character used between every 3 digits to separate thousands. +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{decimal.mark}{The character to be used to indicate the numeric -decimal point.} +decimal point. The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{trim}{Logical, if \code{FALSE}, values are right-justified to a common width (see \code{\link[base:format]{base::format()}}).} @@ -48,7 +51,10 @@ width (see \code{\link[base:format]{base::format()}}).} as wide as a number or \code{+}. Compared to \code{"none"}, adding a figure space can ensure numbers remain properly aligned when they are left- or right-justified. -}} +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{\code{style_negative}}{A string that determines the style of negative numbers: \itemize{ \item \code{"hyphen"} (the default): preceded by a standard hypen \code{-}, e.g. \code{-1}. @@ -56,7 +62,10 @@ right-justified. nicety that ensures \code{-} aligns with the horizontal bar of the the horizontal bar of \code{+}. \item \code{"parens"}, wrapped in parentheses, e.g. \code{(1)}. -}} +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{\code{scale_cut}}{Named numeric vector that allows you to rescale large (or small) numbers and add a prefix. Built-in helpers include: \itemize{ diff --git a/man/label_date.Rd b/man/label_date.Rd index ea06c22d..efdcdd56 100644 --- a/man/label_date.Rd +++ b/man/label_date.Rd @@ -56,9 +56,12 @@ large.} applied to absolute value before \code{style_positive} and \code{style_negative} are processed so that \code{prefix = "$"} will yield (e.g.) \verb{-$1} and \verb{($1)}.} \item{\code{suffix}}{Additional text to display after the number.} - \item{\code{big.mark}}{Character used between every 3 digits to separate thousands.} + \item{\code{big.mark}}{Character used between every 3 digits to separate thousands. +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{\code{decimal.mark}}{The character to be used to indicate the numeric -decimal point.} +decimal point. The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{\code{style_positive}}{A string that determines the style of positive numbers: \itemize{ \item \code{"none"} (the default): no change, e.g. \code{1}. @@ -67,7 +70,10 @@ decimal point.} as wide as a number or \code{+}. Compared to \code{"none"}, adding a figure space can ensure numbers remain properly aligned when they are left- or right-justified. -}} +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{\code{style_negative}}{A string that determines the style of negative numbers: \itemize{ \item \code{"hyphen"} (the default): preceded by a standard hypen \code{-}, e.g. \code{-1}. @@ -75,7 +81,10 @@ right-justified. nicety that ensures \code{-} aligns with the horizontal bar of the the horizontal bar of \code{+}. \item \code{"parens"}, wrapped in parentheses, e.g. \code{(1)}. -}} +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{\code{trim}}{Logical, if \code{FALSE}, values are right-justified to a common width (see \code{\link[base:format]{base::format()}}).} }} diff --git a/man/label_number.Rd b/man/label_number.Rd index cb91f2a9..322f20db 100644 --- a/man/label_number.Rd +++ b/man/label_number.Rd @@ -10,10 +10,10 @@ label_number( scale = 1, prefix = "", suffix = "", - big.mark = " ", - decimal.mark = ".", - style_positive = c("none", "plus", "space"), - style_negative = c("hyphen", "minus", "parens"), + big.mark = NULL, + decimal.mark = NULL, + style_positive = NULL, + style_negative = NULL, scale_cut = NULL, trim = TRUE, ... @@ -49,10 +49,13 @@ processed so that \code{prefix = "$"} will yield (e.g.) \verb{-$1} and \verb{($1 \item{suffix}{Additional text to display after the number.} -\item{big.mark}{Character used between every 3 digits to separate thousands.} +\item{big.mark}{Character used between every 3 digits to separate thousands. +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{decimal.mark}{The character to be used to indicate the numeric -decimal point.} +decimal point. The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{style_positive}{A string that determines the style of positive numbers: \itemize{ @@ -62,7 +65,10 @@ decimal point.} as wide as a number or \code{+}. Compared to \code{"none"}, adding a figure space can ensure numbers remain properly aligned when they are left- or right-justified. -}} +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{style_negative}{A string that determines the style of negative numbers: \itemize{ @@ -71,7 +77,10 @@ right-justified. nicety that ensures \code{-} aligns with the horizontal bar of the the horizontal bar of \code{+}. \item \code{"parens"}, wrapped in parentheses, e.g. \code{(1)}. -}} +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{scale_cut}{Named numeric vector that allows you to rescale large (or small) numbers and add a prefix. Built-in helpers include: diff --git a/man/label_number_si.Rd b/man/label_number_si.Rd index fd8c8ece..c3a9eeaf 100644 --- a/man/label_number_si.Rd +++ b/man/label_number_si.Rd @@ -28,9 +28,12 @@ prefix.} \item{\code{prefix}}{Additional text to display before the number. The suffix is applied to absolute value before \code{style_positive} and \code{style_negative} are processed so that \code{prefix = "$"} will yield (e.g.) \verb{-$1} and \verb{($1)}.} - \item{\code{big.mark}}{Character used between every 3 digits to separate thousands.} + \item{\code{big.mark}}{Character used between every 3 digits to separate thousands. +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{\code{decimal.mark}}{The character to be used to indicate the numeric -decimal point.} +decimal point. The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{\code{style_positive}}{A string that determines the style of positive numbers: \itemize{ \item \code{"none"} (the default): no change, e.g. \code{1}. @@ -39,7 +42,10 @@ decimal point.} as wide as a number or \code{+}. Compared to \code{"none"}, adding a figure space can ensure numbers remain properly aligned when they are left- or right-justified. -}} +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{\code{style_negative}}{A string that determines the style of negative numbers: \itemize{ \item \code{"hyphen"} (the default): preceded by a standard hypen \code{-}, e.g. \code{-1}. @@ -47,7 +53,10 @@ right-justified. nicety that ensures \code{-} aligns with the horizontal bar of the the horizontal bar of \code{+}. \item \code{"parens"}, wrapped in parentheses, e.g. \code{(1)}. -}} +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{\code{scale_cut}}{Named numeric vector that allows you to rescale large (or small) numbers and add a prefix. Built-in helpers include: \itemize{ diff --git a/man/label_ordinal.Rd b/man/label_ordinal.Rd index 471c0ebd..77da0587 100644 --- a/man/label_ordinal.Rd +++ b/man/label_ordinal.Rd @@ -7,13 +7,7 @@ \alias{ordinal_spanish} \title{Label ordinal numbers (1st, 2nd, 3rd, etc)} \usage{ -label_ordinal( - prefix = "", - suffix = "", - big.mark = " ", - rules = ordinal_english(), - ... -) +label_ordinal(prefix = "", suffix = "", big.mark = NULL, rules = NULL, ...) ordinal_english() @@ -24,7 +18,9 @@ ordinal_spanish() \arguments{ \item{prefix, suffix}{Symbols to display before and after value.} -\item{big.mark}{Character used between every 3 digits to separate thousands.} +\item{big.mark}{Character used between every 3 digits to separate thousands. +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{rules}{Named list of regular expressions, matched in order. Name gives suffix, and value specifies which numbers to match.} @@ -42,7 +38,8 @@ Applied to rescaled data.} formatting. This is useful if the underlying data is very small or very large.} \item{\code{decimal.mark}}{The character to be used to indicate the numeric -decimal point.} +decimal point. The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{\code{style_positive}}{A string that determines the style of positive numbers: \itemize{ \item \code{"none"} (the default): no change, e.g. \code{1}. @@ -51,7 +48,10 @@ decimal point.} as wide as a number or \code{+}. Compared to \code{"none"}, adding a figure space can ensure numbers remain properly aligned when they are left- or right-justified. -}} +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{\code{style_negative}}{A string that determines the style of negative numbers: \itemize{ \item \code{"hyphen"} (the default): preceded by a standard hypen \code{-}, e.g. \code{-1}. @@ -59,7 +59,10 @@ right-justified. nicety that ensures \code{-} aligns with the horizontal bar of the the horizontal bar of \code{+}. \item \code{"parens"}, wrapped in parentheses, e.g. \code{(1)}. -}} +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{\code{scale_cut}}{Named numeric vector that allows you to rescale large (or small) numbers and add a prefix. Built-in helpers include: \itemize{ diff --git a/man/label_percent.Rd b/man/label_percent.Rd index a705538c..4fe707a8 100644 --- a/man/label_percent.Rd +++ b/man/label_percent.Rd @@ -9,8 +9,8 @@ label_percent( scale = 100, prefix = "", suffix = "\%", - big.mark = " ", - decimal.mark = ".", + big.mark = NULL, + decimal.mark = NULL, trim = TRUE, ... ) @@ -33,10 +33,13 @@ processed so that \code{prefix = "$"} will yield (e.g.) \verb{-$1} and \verb{($1 \item{suffix}{Additional text to display after the number.} -\item{big.mark}{Character used between every 3 digits to separate thousands.} +\item{big.mark}{Character used between every 3 digits to separate thousands. +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{decimal.mark}{The character to be used to indicate the numeric -decimal point.} +decimal point. The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{trim}{Logical, if \code{FALSE}, values are right-justified to a common width (see \code{\link[base:format]{base::format()}}).} @@ -52,7 +55,10 @@ width (see \code{\link[base:format]{base::format()}}).} as wide as a number or \code{+}. Compared to \code{"none"}, adding a figure space can ensure numbers remain properly aligned when they are left- or right-justified. -}} +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{\code{style_negative}}{A string that determines the style of negative numbers: \itemize{ \item \code{"hyphen"} (the default): preceded by a standard hypen \code{-}, e.g. \code{-1}. @@ -60,7 +66,10 @@ right-justified. nicety that ensures \code{-} aligns with the horizontal bar of the the horizontal bar of \code{+}. \item \code{"parens"}, wrapped in parentheses, e.g. \code{(1)}. -}} +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{\code{scale_cut}}{Named numeric vector that allows you to rescale large (or small) numbers and add a prefix. Built-in helpers include: \itemize{ diff --git a/man/label_pvalue.Rd b/man/label_pvalue.Rd index ae9e2b83..78b7a4f6 100644 --- a/man/label_pvalue.Rd +++ b/man/label_pvalue.Rd @@ -6,7 +6,7 @@ \usage{ label_pvalue( accuracy = 0.001, - decimal.mark = ".", + decimal.mark = NULL, prefix = NULL, add_p = FALSE ) @@ -20,7 +20,8 @@ difference between adjacent values. Applied to rescaled data.} \item{decimal.mark}{The character to be used to indicate the numeric -decimal point.} +decimal point. The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{prefix}{A character vector of length 3 giving the prefixes to put in front of numbers. The default values are \code{c("<", "", ">")} diff --git a/man/label_scientific.Rd b/man/label_scientific.Rd index 97db3367..b28a8608 100644 --- a/man/label_scientific.Rd +++ b/man/label_scientific.Rd @@ -9,7 +9,7 @@ label_scientific( scale = 1, prefix = "", suffix = "", - decimal.mark = ".", + decimal.mark = NULL, trim = TRUE, ... ) @@ -24,7 +24,8 @@ large.} \item{prefix, suffix}{Symbols to display before and after value.} \item{decimal.mark}{The character to be used to indicate the numeric -decimal point.} +decimal point. The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{trim}{Logical, if \code{FALSE}, values are right-justified to a common width (see \code{\link[base:format]{base::format()}}).} diff --git a/man/number.Rd b/man/number.Rd index 2ac5a42c..57696e96 100644 --- a/man/number.Rd +++ b/man/number.Rd @@ -14,10 +14,10 @@ number( scale = 1, prefix = "", suffix = "", - big.mark = " ", - decimal.mark = ".", - style_positive = c("none", "plus", "space"), - style_negative = c("hyphen", "minus", "parens"), + big.mark = NULL, + decimal.mark = NULL, + style_positive = NULL, + style_negative = NULL, scale_cut = NULL, trim = TRUE, ... @@ -49,10 +49,13 @@ processed so that \code{prefix = "$"} will yield (e.g.) \verb{-$1} and \verb{($1 \item{suffix}{Additional text to display after the number.} -\item{big.mark}{Character used between every 3 digits to separate thousands.} +\item{big.mark}{Character used between every 3 digits to separate thousands. +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{decimal.mark}{The character to be used to indicate the numeric -decimal point.} +decimal point. The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{style_positive}{A string that determines the style of positive numbers: \itemize{ @@ -62,7 +65,10 @@ decimal point.} as wide as a number or \code{+}. Compared to \code{"none"}, adding a figure space can ensure numbers remain properly aligned when they are left- or right-justified. -}} +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{style_negative}{A string that determines the style of negative numbers: \itemize{ @@ -71,7 +77,10 @@ right-justified. nicety that ensures \code{-} aligns with the horizontal bar of the the horizontal bar of \code{+}. \item \code{"parens"}, wrapped in parentheses, e.g. \code{(1)}. -}} +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{scale_cut}{Named numeric vector that allows you to rescale large (or small) numbers and add a prefix. Built-in helpers include: diff --git a/man/number_options.Rd b/man/number_options.Rd new file mode 100644 index 00000000..d9c81aa5 --- /dev/null +++ b/man/number_options.Rd @@ -0,0 +1,79 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/label-number.R +\name{number_options} +\alias{number_options} +\title{Number options} +\usage{ +number_options( + decimal.mark = ".", + big.mark = " ", + style_positive = c("none", "plus", "space"), + style_negative = c("hyphen", "minus", "parens"), + currency.prefix = "$", + currency.suffix = "", + currency.decimal.mark = decimal.mark, + currency.big.mark = setdiff(c(".", ","), currency.decimal.mark)[1], + ordinal.rules = ordinal_english() +) +} +\arguments{ +\item{decimal.mark}{The character to be used to indicate the numeric +decimal point. The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} + +\item{big.mark}{Character used between every 3 digits to separate thousands. +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} + +\item{style_positive}{A string that determines the style of positive numbers: +\itemize{ +\item \code{"none"} (the default): no change, e.g. \code{1}. +\item \code{"plus"}: preceded by \code{+}, e.g. \code{+1}. +\item \code{"space"}: preceded by a Unicode "figure space", i.e., a space equally +as wide as a number or \code{+}. Compared to \code{"none"}, adding a figure space +can ensure numbers remain properly aligned when they are left- or +right-justified. +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} + +\item{style_negative}{A string that determines the style of negative numbers: +\itemize{ +\item \code{"hyphen"} (the default): preceded by a standard hypen \code{-}, e.g. \code{-1}. +\item \code{"minus"}, uses a proper Unicode minus symbol. This is a typographical +nicety that ensures \code{-} aligns with the horizontal bar of the +the horizontal bar of \code{+}. +\item \code{"parens"}, wrapped in parentheses, e.g. \code{(1)}. +} + +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} + +\item{currency.prefix, currency.suffix, currency.decimal.mark, currency.big.mark}{Settings for \code{\link[=label_currency]{label_currency()}} passed on without the \code{currency.}-prefix.} + +\item{ordinal.rules}{Setting for \code{\link[=label_ordinal]{label_ordinal()}} passed on without the +\code{ordinal.}-prefix.} +} +\value{ +The old options invisibly +} +\description{ +Control the settings for formatting numbers globally. +} +\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) +} diff --git a/man/ordinal_format.Rd b/man/ordinal_format.Rd index c2a692a3..1de83ed9 100644 --- a/man/ordinal_format.Rd +++ b/man/ordinal_format.Rd @@ -5,27 +5,16 @@ \alias{ordinal} \title{Superseded interface to \code{label_ordinal()}} \usage{ -ordinal_format( - prefix = "", - suffix = "", - big.mark = " ", - rules = ordinal_english(), - ... -) +ordinal_format(prefix = "", suffix = "", big.mark = NULL, rules = NULL, ...) -ordinal( - x, - prefix = "", - suffix = "", - big.mark = " ", - rules = ordinal_english(), - ... -) +ordinal(x, prefix = "", suffix = "", big.mark = " ", rules = NULL, ...) } \arguments{ \item{prefix, suffix}{Symbols to display before and after value.} -\item{big.mark}{Character used between every 3 digits to separate thousands.} +\item{big.mark}{Character used between every 3 digits to separate thousands. +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{rules}{Named list of regular expressions, matched in order. Name gives suffix, and value specifies which numbers to match.} diff --git a/man/percent_format.Rd b/man/percent_format.Rd index aad6ad30..26120995 100644 --- a/man/percent_format.Rd +++ b/man/percent_format.Rd @@ -10,8 +10,8 @@ percent_format( scale = 100, prefix = "", suffix = "\%", - big.mark = " ", - decimal.mark = ".", + big.mark = NULL, + decimal.mark = NULL, trim = TRUE, ... ) @@ -22,8 +22,8 @@ percent( scale = 100, prefix = "", suffix = "\%", - big.mark = " ", - decimal.mark = ".", + big.mark = NULL, + decimal.mark = NULL, trim = TRUE, ... ) @@ -46,10 +46,13 @@ processed so that \code{prefix = "$"} will yield (e.g.) \verb{-$1} and \verb{($1 \item{suffix}{Additional text to display after the number.} -\item{big.mark}{Character used between every 3 digits to separate thousands.} +\item{big.mark}{Character used between every 3 digits to separate thousands. +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{decimal.mark}{The character to be used to indicate the numeric -decimal point.} +decimal point. The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{trim}{Logical, if \code{FALSE}, values are right-justified to a common width (see \code{\link[base:format]{base::format()}}).} diff --git a/man/pvalue_format.Rd b/man/pvalue_format.Rd index 71e4436a..bea3377b 100644 --- a/man/pvalue_format.Rd +++ b/man/pvalue_format.Rd @@ -7,12 +7,12 @@ \usage{ pvalue_format( accuracy = 0.001, - decimal.mark = ".", + decimal.mark = NULL, prefix = NULL, add_p = FALSE ) -pvalue(x, accuracy = 0.001, decimal.mark = ".", prefix = NULL, add_p = FALSE) +pvalue(x, accuracy = 0.001, decimal.mark = NULL, prefix = NULL, add_p = FALSE) } \arguments{ \item{accuracy}{A number to round to. Use (e.g.) \code{0.01} to show 2 decimal @@ -23,7 +23,8 @@ difference between adjacent values. Applied to rescaled data.} \item{decimal.mark}{The character to be used to indicate the numeric -decimal point.} +decimal point. The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{prefix}{A character vector of length 3 giving the prefixes to put in front of numbers. The default values are \code{c("<", "", ">")} diff --git a/man/scientific_format.Rd b/man/scientific_format.Rd index dfa483d9..e0b2e715 100644 --- a/man/scientific_format.Rd +++ b/man/scientific_format.Rd @@ -10,7 +10,7 @@ scientific_format( scale = 1, prefix = "", suffix = "", - decimal.mark = ".", + decimal.mark = NULL, trim = TRUE, ... ) @@ -21,7 +21,7 @@ scientific( scale = 1, prefix = "", suffix = "", - decimal.mark = ".", + decimal.mark = NULL, trim = TRUE, ... ) @@ -36,7 +36,8 @@ large.} \item{prefix, suffix}{Symbols to display before and after value.} \item{decimal.mark}{The character to be used to indicate the numeric -decimal point.} +decimal point. The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{trim}{Logical, if \code{FALSE}, values are right-justified to a common width (see \code{\link[base:format]{base::format()}}).} diff --git a/man/unit_format.Rd b/man/unit_format.Rd index edbaad83..615a2411 100644 --- a/man/unit_format.Rd +++ b/man/unit_format.Rd @@ -11,8 +11,8 @@ unit_format( unit = "m", sep = " ", suffix = paste0(sep, unit), - big.mark = " ", - decimal.mark = ".", + big.mark = NULL, + decimal.mark = NULL, trim = TRUE, ... ) @@ -39,10 +39,13 @@ processed so that \code{prefix = "$"} will yield (e.g.) \verb{-$1} and \verb{($1 \item{suffix}{Additional text to display after the number.} -\item{big.mark}{Character used between every 3 digits to separate thousands.} +\item{big.mark}{Character used between every 3 digits to separate thousands. +The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{decimal.mark}{The character to be used to indicate the numeric -decimal point.} +decimal point. The default (\code{NULL}) retrieves the setting from the +\link[=number_options]{number options}.} \item{trim}{Logical, if \code{FALSE}, values are right-justified to a common width (see \code{\link[base:format]{base::format()}}).}