formatDL
Format Description Lists

Description

Formats vectors of tags and their descriptions to a 2-column table or a tagged list.

Usage

formatDL(x, y, style = c("table", "list"), 
    width = 0.9 * getOption("width"), indent = NULL)

Arguments

xone of the following.
  • a character vector containing tags.
  • a length-2 list containing the tag and description vectors.
  • a 2-column character matrix containing the tag and description columns.
  • a character vector with names. (Names are tags, and elements are descriptions. The lengths of tags and descriptions must be same.)

y a character vector containing the corresponding descriptions. Ignored if x is a list or a matrix. (If x is a vector with names and y is supplied, then the names in x are ignored, its values are used as the tags, and the values in y are used as the descriptions.)
style a character string specifying the format style. Must be "table" or "list". Partial matching is allowed.
width a small positive integer. Line breaks are inserted into the descriptions so that, if possible, when the descriptions are printed with cat(sep="\n", formatDL(..., width=width)) the printed lines are no longer than width characters.
indent a non-negative integer. For the "table" style, this value specifies the indention of the description lines: both the first and the continuation lines. For the "list" style, this value specifies the indentation of continuation lines. (The first line always starts right after the colon that follows the tag.)

indent must not be greater than width/2. The default value, NULL, specifies width/3 for the "table" style and width/9 for the "list" style.

Details

The x and y are coerced to the data type character before being formatted. For a "table" style format, x and y are formatted as a table with 2 columns. For a "list" style format, x and y are merged with the separator ":".
Value
returns a character vector with the formatted items and descriptions.
See Also
formatC, strwrap.
Examples
cat(sep="\n", formatDL(c(One="First number",
                         Two="Second number",
                         Three="Third number")))
# 3 more ways to make the same thing
cat(sep="\n", formatDL(c("One", "Two", "Three"),
                       c("First number",
                         "Second number",
                         "Third number")))
cat(sep="\n", formatDL(list(c("One", "Two", "Three"),
                            c("First number",
                              "Second number",
                              "Third number"))))
cat(sep="\n", formatDL(cbind(c("One", "Two", "Three"),
                            c("First number",
                              "Second number",
                              "Third number"))))
# 2 ways to reduce space between tags and descriptions
cat(sep="\n", formatDL(c(One="First number",
                         Two="Second number",
                         Three="Third number"),
                       indent=10))
cat(sep="\n", formatDL(c(One="First number",
                         Two="Second number",
                         Three="Third number"),
                       width=24))

# "list" style cat(sep="\n", formatDL(c(One="First number", Two="Second number", Third="Third number"), style="list"))

# line wrapping cat(sep="\n", formatDL(c(One="The most important concern", Two="A secondary concern", Miscellaneous="Matters of little interest to us"), width=35)) cat(sep="\n", formatDL(c(One="The most important concern", Two="A secondary concern", Miscellaneous="Matters of little interest to us"), width=35, style="list"))

Package base version 6.1.1-7
Package Index