cn: Number-aware Strings with Substitution

Description Usage Arguments Details See Also

View source: R/cn.r

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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


jamesdunham/concatenate documentation built on May 18, 2019, 11:19 a.m.