Learn R Programming

multiRec (version 1.0.6)

collapse: Collapse a vector into a string

Description

Collapses a vector into a comma delimited string with the word 'and' between the last two entries.

Usage

collapse(
  x,
  sep = ", ",
  maxItems = 10,
  last = c("%1$s and %2$s", "%1$s, %2$s and %3$d more",
    "%1$s, %2$s and %3$d more"),
  quote = NULL
)

Value

a string

Arguments

x

the vector

sep

the separator for all but the last entry

maxItems

If there are more than this many items, only the first maxItems are displayed.

last

three sprintf formats (see details)

quote

A function used to quote the elements (such as sQuote or dQuote) or NULL

Details

The last= argument contains three sprintf formats. The first is used if there are fewer than maxItems items, the second if there are maxItems+1 items, the first if there are more than maxItems+1 items.

The arguments are passed as the last, shown.