powered by
This function is intended to be convert any R object to a short descriptive string, e.g. in base::print() functions.
base::print()
The following rules apply:
if x is atomic() with length 0 or 1: printed as-is.
x
atomic()
if x is atomic() with length greater than 1, x is collapsed with ",", and the resulting string is truncated to trunc_width characters.
","
trunc_width
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.
as_short_string(x, width = 30L, num_format = "%.4g")
(character(1)).
character(1)
(any) Arbitrary object.
any
(integer(1)) Truncate strings to width width.
integer(1)
width
(character(1)) Used to format numerical scalars via base::sprintf().
base::sprintf()
as_short_string(list(a = 1, b = NULL, "foo", c = 1:10))
Run the code above in your browser using DataLab