Description Usage Arguments Value Author(s) Examples
A single function to facilitate the correct pluralization and internationalization of R messages.
1 |
n |
A numerical value, passed to |
msg1 |
A character string containing an English-language message when
|
msg2 |
A character string containing an English-language message when
|
... |
Additional arguments passed to |
domain |
A character string specifying a gettext domain, passed to
|
A character vector.
Thomas J. Leeper
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # simple pluralization
nsprintf(0:3, "there is one apple", "there are %d apples")
# additional arguments to `sprintf()`
# count the number of objects in each environment on the search path
envs <- search()
n <- vapply(envs, function(env) length(ls(env)), integer(1))
nsprintf(n, "there is %d variable in %s",
"there are %d variables in %s", envs)
# nested nsprintf:
n_objects <- 6
k_chosen <- seq(0, n_objects)
n_combinations <- choose(n_objects, k_chosen)
nsprintf(
n_combinations,
"there is %d combination of %s chosen from a set of size %d",
"there are %d combinations of %s chosen from a set of size %d",
nsprintf(k_chosen, "%d object", "%d objects"),
n_objects
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.