Description Usage Arguments Details Value Examples
View source: R/utils_strings.R
Compose text strings conditional on values of an object.
1 | FormatText(x, ..., quote = "'")
|
x |
an integer-valued numeric scalar or a logical vector. In the former case, indicates a number of items; in the latter case, indicates which items in a vector were affected. May have the 'names' attribute set. |
... |
one or more character vectors that are pasted together (collapsed) after concatenating the vectors one after another. |
quote |
the quote character to use. |
The function replaces the following special character patterns:
{a|b
}: 'a' if sum(x) == 1
and 'b' otherwise.
{z|a|b}
: 'z' if sum(x) == 0
, otherwise works
like {a|b}
.
$N
: sum(x)
.
$P
: sprintf("%.1f", 100 * mean(x))
.
$L
: length(x)
. The following patterns are
replaced with comma-separated lists of:
$w
: which(x)
.
$W
: which(x)
, each item quoted.
$x
: names(x)[which(x)]
.
$X
: names(x)[which(x)]
, each item quoted.
Exception: These four patterns output only up to the Kth item, where
K = getOption('FormatTextMaxOutput', default=7L)
.
A character string.
1 2 3 4 | ## Not run:
FormatText(n, "There {is|are} {no|one|$N} item{|s}.")
FormatText(is.na(x), "Found $N NAs ($P% of all $L) in rows $w")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.