From 8afa7b6505029784c633f788f74d13221a18df6f Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Mon, 25 Sep 2023 15:05:14 -0400 Subject: [PATCH] Specify format options --- R/formatting_functions.R | 6 +++--- man/format_sigfig.Rd | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/R/formatting_functions.R b/R/formatting_functions.R index 914025ea09..32b7ea7d19 100644 --- a/R/formatting_functions.R +++ b/R/formatting_functions.R @@ -215,9 +215,8 @@ format_xx <- function(str) { #' #' @param sigfig (`integer`)\cr number of significant figures to display. #' @param format (`character`)\cr the format label (string) to apply when printing the value. Decimal -#' places in string are ignored in favor of formatting by significant figures. See -#' [formatters::list_valid_format_labels()] for a list of valid formats (only those with no decimal -#' points can be applied). +#' places in string are ignored in favor of formatting by significant figures. Formats options are: +#' `"xx"`, `"xx / xx"`, `"(xx, xx)"`, `"xx - xx"`, and `"xx (xx)"`. #' @param num_fmt (`character`)\cr numeric format modifiers to apply to the value. Defaults to `"fg"` for #' standard significant figures formatting - fixed (non-scientific notation) format (`"f"`) #' and `sigfig` equal to number of significant figures instead of decimal places (`"g"`). See the @@ -238,6 +237,7 @@ format_xx <- function(str) { #' @export format_sigfig <- function(sigfig, format = "xx", num_fmt = "fg") { checkmate::assert_integerish(sigfig) + checkmate::assert_choice(format, c("xx", "xx / xx", "(xx, xx)", "xx - xx", "xx (xx)")) function(x, ...) { if (!is.numeric(x)) stop("`format_sigfig` cannot be used for non-numeric values. Please choose another format.") num <- formatC(signif(x, digits = sigfig), digits = sigfig, format = num_fmt, flag = "#") diff --git a/man/format_sigfig.Rd b/man/format_sigfig.Rd index 1e0457bdef..2177142c96 100644 --- a/man/format_sigfig.Rd +++ b/man/format_sigfig.Rd @@ -10,9 +10,8 @@ format_sigfig(sigfig, format = "xx", num_fmt = "fg") \item{sigfig}{(\code{integer})\cr number of significant figures to display.} \item{format}{(\code{character})\cr the format label (string) to apply when printing the value. Decimal -places in string are ignored in favor of formatting by significant figures. See -\code{\link[formatters:list_formats]{formatters::list_valid_format_labels()}} for a list of valid formats (only those with no decimal -points can be applied).} +places in string are ignored in favor of formatting by significant figures. Formats options are: +\code{"xx"}, \code{"xx / xx"}, \code{"(xx, xx)"}, \code{"xx - xx"}, and \code{"xx (xx)"}.} \item{num_fmt}{(\code{character})\cr numeric format modifiers to apply to the value. Defaults to \code{"fg"} for standard significant figures formatting - fixed (non-scientific notation) format (\code{"f"})