Learn R Programming

multiRec (version 1.0.6)

paste.and: 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

paste.and(
  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.

Examples

Run this code
multiRec:::paste.and(1:4)  # "1, 2, 3 and 4"
multiRec:::paste.and(1:16, maxItems=4) # "1, 2, 3, 4 and 12 more"

Run the code above in your browser using DataLab