Pastes formatted x if numeric, otherwise x unmodified.
Circumvents R's automatic scientific notation.
If a number is nearly whole (see is_nearly_whole()), it is rounded to have
zero decimal places. Otherwise, numbers >= 1 are rounded to 1 decimal place;
numbers < 1 are rounded to have 2 significant digits.
Usage
format_number(x, nsmall = 1, signif_precise = 2)
Value
formatted x if numeric, otherwise x unmodified.
Arguments
x
inline code
nsmall
number of digits after the decimal point to round to when x
is not nearly whole but x >= 1.
signif_precise
number of significant digits to use when x is not
nearly whole
format_number(0.0256)
format_number(.Machine$double.eps^0.5)
format_number(100000.08)
format_number(1.00000000000000000001)
format_number("this is a string")