This function is intended to be convert any R object to a short descriptive string,
e.g. in base::print()
functions.
The following rules apply:
if
x
isatomic()
with length 0 or 1: printed as-is.if
x
isatomic()
with length greater than 1,x
is collapsed with","
, and the resulting string is truncated totrunc_width
characters.if
x
is an expression: converted to character.Otherwise: the class is printed.
If x
is a list, the above rules are applied (non-recursively) to its elements.
Arguments
- x
(
any
)
Arbitrary object.- width
(
integer(1)
)
Truncate strings to widthwidth
.- num_format
(
character(1)
)
Used to format numerical scalars viabase::sprintf()
.
Examples
as_short_string(list(a = 1, b = NULL, "foo", c = 1:10))
#> [1] "a=1, b=<NULL>, <unnamed>=foo, c=1,2,3,4,5,6,7,8,9,10"