cn {concatenate}R Documentation

Number-aware Strings with Substitution

Description

cn combines grammatical number awareness as in ngettext with sprintf-like substitution for comma-concatenated text.

Usage

cn(object, singular, plural = singular)

cn_and(object, singular, plural = singular)

cn_or(object, singular, plural = singular)

## S4 method for signature 'data.frame'
cn(object, singular, plural = singular)

## S4 method for signature 'data.frame'
cn_and(object, singular, plural = singular)

## S4 method for signature 'data.frame'
cn_or(object, singular, plural = singular)

Arguments

object

An n-vector, or data.frame with n rows.

singular

The string to return if n = 1.

plural

The string to return if n is in 0, 2, 3, 4, ...

Details

Like ngettext, this function returns one string to be used with a singular referent and another with a plural referent. cn chooses between the two based on the length of its first argument, object, or if object is a data.frame, its row count.

Two substitions are made sprintf-style. "%n" is replaced with the number of object, and "%c" is replaced with the comma-concatenated values of object, as in cc.

cn_and uses cc_and instead of cc; cn_or uses cc_or.

See Also

cc


[Package concatenate version 1.0.0 Index]