Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

as_short_string

Convert R Object to a Descriptive String


Description

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 is atomic() with length 0 or 1: printed as-is.

  • if x is atomic() with length greater than 1, x is collapsed with ",", and the resulting string is truncated to trunc_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.

Usage

as_short_string(x, width = 30L, num_format = "%.4g")

Arguments

x

(any)
Arbitrary object.

width

(integer(1))
Truncate strings to width width.

num_format

(character(1))
Used to format numerical scalars via base::sprintf().

Value

(character(1)).

Examples

as_short_string(list(a = 1, b = NULL, "foo", c = 1:10))

mlr3misc

Helper Functions for 'mlr3'

v0.10.0
LGPL-3
Authors
Michel Lang [cre, aut] (<https://orcid.org/0000-0001-9754-0393>), Patrick Schratz [aut] (<https://orcid.org/0000-0003-0748-6624>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.