signif_beautify: Convert a number to a string in significant-figure form

View source: R/utils_signifBeautify.R

signif_beautifyR Documentation

Convert a number to a string in significant-figure form

Description

Standard significant figure functions (such as signif, format) either do not output a string format (thereby excluding necessary trailing decimals & zeros), or do not correctly pad the number with the correct number of trailing zeros. This function aims to address these issues.

Usage

signif_beautify(
  n,
  sig_digits,
  justify_mode,
  decimal_mark = ".",
  big_mark = ",",
  big_interval = 3,
  pad_zeros = F,
  justify_char = " ",
  nsmall = NULL
)

Arguments

n

Number or numeric vector to convert

sig_digits

Number of significant digits. If NA or NULL, the input number is not changed.

justify_mode

Mode to use for justifying a vector of values. Can be "l" (left), "c" (center), "r" (right), or "d" (decimal).

decimal_mark

Character to use as the decimal marker.

big_mark

If not blank, character to use in grouping every big_interval digits before the decimal marker.

big_interval

Number of digits between each big_mark, if used.

pad_zeros

Whether to add extra trailing zeros and/or a decimal to force number of significant digits (even if the original number did not have that many digits). Default = FALSE.

justify_char

Character (or string) used to pad strings.

nsmall

Forces output to have nsmall digits after the decimal. If there are fewer significant digits than total digits after including nsmall, the number of significant digits is increased.


adamleejohnson/R-ajtools documentation built on April 4, 2022, 7:24 a.m.