format_engr {formatdown} | R Documentation |
Format engineering notation
Description
Convert a numeric vector to a character vector in which the numbers are formatted in power-of-ten notation in engineering form and delimited for rendering as inline equations in an R markdown document.
Usage
format_engr(
x,
digits = 4,
...,
omit_power = c(-1, 2),
set_power = NULL,
delim = formatdown_options("delim"),
size = formatdown_options("size"),
decimal_mark = formatdown_options("decimal_mark"),
small_mark = formatdown_options("small_mark"),
small_interval = formatdown_options("small_interval"),
whitespace = formatdown_options("whitespace")
)
Arguments
x |
Number or numbers to be formatted. Can be a single number, a vector, or a column of a data frame. |
digits |
Integer from 1 through 20 that controls the number of
significant digits in printed numeric values. Passed to |
... |
Not used for values; forces subsequent arguments to be referable only by name. |
omit_power |
Numeric vector |
set_power |
Integer, length 1. Formats all values in |
delim |
Character, length 1 or 2, to define the left and right math
markup delimiters. The default setting, |
size |
Character, length 1, to assign a font size. If not empty, adds
a font size macro to the markup inside the math delimiters. Possible
values are |
decimal_mark |
Character, length 1, to assign the decimal marker.
Possible values are a period |
small_mark |
Character, length 1, used as the mark between every
|
small_interval |
Integer, length 1, that defines the number of digits
(default 5) in groups separated by |
whitespace |
Character, length 1, to define the LaTeX-style
math-mode macro to preserve a horizontal space between words of text or
between physical-unit abbreviations when formatting numbers of class
"units". Default is |
Details
In engineering notation, all exponents are multiples of three.
format_engr()
is a wrapper for the more general function format_numbers()
.
Where defaults are defined by formatdown_options()
, users may reassign
the arguments locally in the function call or globally using
formatdown_options()
.
Arguments after the dots (...
) must be referred to by name.
Value
A character vector in which numbers are formatted in power-of-ten notation in engineering form and delimited for rendering as inline equations in an R markdown document.
See Also
Other format_*:
format_dcml()
,
format_numbers()
,
format_sci()
,
format_text()
Examples
# input: single number
x <- 6.0221E+23
format_numbers(x)
# input: units class
x <- 103400
units(x) <- "N m2 C-2"
format_numbers(x)
# input: vector
data("metals", package = "formatdown")
x <- metals$dens
format_numbers(x)
# significant digits
x <- 9.75358e+5
format_numbers(x, 2)
format_numbers(x, 3)
format_numbers(x, 4)
# format & wrappers: format_engr(), format_sci(), format_dcml()
x <- 6.0221E+23
format_numbers(x, format = "engr")
format_engr(x)
format_numbers(x, format = "sci")
format_sci(x)
x <- 103400
format_numbers(x, format = "dcml")
format_dcml(x)
# input: data frame
x <- metals[, c("thrm_exp", "thrm_cond")]
as.data.frame(apply(x, 2, format_sci, digits = 3))
# omit_power
x <- 103400
format_sci(x, omit_power = c(-1, 2)) # default
format_sci(x, omit_power = c(-1, 5))
format_sci(x, omit_power = 5) # equivalent to omit_power = c(5, 5)
x <- 1.2
format_sci(x, omit_power = NULL)
# set_power
format_sci(x, set_power = NULL) # default
format_sci(x, set_power = 3)
# set_power overrides format
x <- 6.0221E+23
format_engr(x)
format_engr(x, set_power = 24L)
format_sci(x)
format_sci(x, set_power = 24L)
# set_power overrides omit_power
x <- 101300
format_sci(x, omit_power = 5)
format_sci(x, omit_power = 5, set_power = 2)
format_sci(x, omit_power = 2)
format_sci(x, omit_power = 2, set_power = 2)
# decimal format ignores set_power
x <- 103400
format_numbers(x, format = "dcml")
format_numbers(x, format = "dcml", set_power = 3)