Usage
format_vector(
x = vector(),
label = NULL,
level = 0L,
indent = 1L,
fill_names = FALSE,
null = "<null>",
empty = "<empty>",
validate = TRUE
)Arguments
- x
A vector of any atomic mode, a list, or a pairlist. It can be empty and it can contain NA values.
- label
A
NULL, or a non-empty and non-NA character string. A top descriptive label forx. It is used to preserve, and output all names in recursive calls. The value passed tolabelis considered to be atlevel0, and is not indented.- level
A non-NA integer value. The current depth, or current nesting level to use for indentation purposes.
- indent
A non-NA integer value. The number of single space(s) to use for each
levelwhen indenting name/value pairs.- fill_names
A non-NA logical value. Should
NULLand empty names be replaced by names created from the elements' underlying positions? Positions are relative to eachlevel.- null
A non-empty and non-NA character string. The value to use to represent
NULLand empty parlists (they are conceptually the same thing).- empty
A non-empty and non-NA character string. The value to use to represent empty vectors, excluding
NULL. Seenullabove for the latter. The type of the underlying empty object is added toemptyfor convenience. See Examples below.- validate
A non-NA logical value. Should the arguments be validated before being used? This argument should be left as is.
Value
A character vector, possibly trimmed by str_trim().
Details
format_vector() is an alternative to utils::str() that exposes a much
simpler generic formatting interface and yields terser outputs of name/value
pairs. Indentation is used for nested values.
format_vector() does not attempt to cover all R objects like
utils::str(). Instead, it (merely) focuses on efficiently handling the
types used by transltr. It is the low-level workhorse function of
format.Translator(), format.Text(), and format.Location().