This is inspired by the python function repr
and produces a short
string representation of any R object that is suitable for logging and error
messages. It is a generic so you can implement methods for custom S3 objects.
string_repr(x, width = 32, ...)
# S3 method for `function`
string_repr(x, width = 32L, ...)
# S3 method for data.frame
string_repr(x, width = 32L, ...)
# S3 method for matrix
string_repr(x, width = 32L, ...)
# S3 method for default
string_repr(x, width = 32L, ...)
Any R object.
a scalar integer
passed on to methods
a scalar
character
string_repr(iris)
#> [1] "<data.frame 150x5>"
string_repr(LETTERS)
#> [1] "(A, B, C, D, E, F, G, H, I, J..)"
string_repr(LETTERS, 10)
#> [1] "(A, B..)"