Using sprintf
flexibly format numbers as character strings
encoded for parsing into R expressions or using LaTeX or markdown
notation.
Arguments
- fmt
character as in
sprintf()
.- ...
as in
sprintf()
.- decimal.mark
character If
NULL
orNA
no substitution is attempted and the value returned bysprintf()
is returned as is.- value
numeric The value of the estimate.
- digits
integer Number of digits to which numeric values are formatted.
- format
character One of "e", "f" or "g" for exponential, fixed, or significant digits formatting.
- output.type
character One of "expression", "latex", "tex", "text", "tikz", "markdown".
Details
These functions are used to format the character strings returned,
which can be used as labels in plots. Encoding used for the formatting is
selected by the argument passed to output.type
, thus, supporting
different R graphic devices.
Examples
sprintf_dm("%2.3f", 2.34)
#> [1] "2.340"
sprintf_dm("%2.3f", 2.34, decimal.mark = ",")
#> [1] "2,340"
value2char(2.34)
#> [1] "\"2.3\""
value2char(2.34, digits = 3, format = "g")
#> [1] "\"2.34\""
value2char(2.34, digits = 3, format = "f")
#> [1] "\"2.340\""
value2char(2.34, output.type = "text")
#> [1] "2.3"
value2char(2.34, output.type = "text", format = "f")
#> [1] "2.34"
value2char(2.34, output.type = "text", format = "g")
#> [1] "2.3"