as_shrthnd()
coerces a shrthnd_num()
vector back to a character vector
re-inserting the shorthand tags.
Usage
as_shrthnd(
x,
digits = NULL,
decimal_mark = NULL,
big_mark = NULL,
.pillar = FALSE,
.trim = TRUE,
.full_tag = FALSE
)
Arguments
- x
A
shrthnd_num()
vector- digits
Number of digits to apply to
shrthnd_double
vectors- decimal_mark
The symbol used for decimal marks
- big_mark
The symbol used to separate large numbers
- .pillar
A flag for formatting within the
{pillar}
package- .trim
A flag to remove formatting white space
- .full_tag
A flag to display full shrthnd tag information
Details
When calling as.character()
on a shrthnd_num()
the output is as you
would expect when calling it on a traditional numeric vector, as_shrthnd()
returns a character vector combining the numeric vector and the shorthand
tags.
When digits = NULL
then shrthnd_double
vectors are printed with the
number of digits set in the digits
attribute of the vector, setting
digits
in as_shrthnd()
will override this value.
as_shrthnd()
acts as the underlying formatter for the printing of
shrthnd_num()
vectors to the console, including inside of data.frame()
and tibble::tibble()
objects. When called directly as_shrthnd()
trims
formatting whitespace, set .trim = FALSE
to return a character vector
including formatting whitespace. For ease of display, tags are limited
to three characters and replaced with an ellipsis (...
) if longer, set
.full_tag = FALSE
to show the entire tag in the output vector.
Examples
x <- c("12", "34.567", "[c]", "NA", "56.78[e]", "78.9", "90.123[e]")
sh_x <- shrthnd_num(x, c("[c]", "[e]"), digits = 1)
as_shrthnd(sh_x)
#> [1] "12.0" "34.6" "NA [c]" "NA" "56.8 [e]" "78.9" "90.1 [e]"
as_shrthnd(sh_x, digits = 3)
#> [1] "12.000" "34.567" "NA [c]" "NA" "56.780 [e]"
#> [6] "78.900" "90.123 [e]"