| colorize | R Documentation |
Add ANSI color to a string using the
crayon package, if the R environment accepts color.
This function is needed because some
output cannot be colorized. Color determination
is made by crayon::has_color().
Rdistance results often include units, e.g., "25 [m]".
Only colorize the numbers, not the units. Everything between the
first set of square brackets ([...]) is NOT colorized.
Subsequent sets of brackets (e.g., "25 [m] + 30 [ft]") ARE colorized
(i.e., "[ft]" is color).
colorize(STR, col = NULL, bg = NULL)
STR |
A vector of strings to colorize. |
col |
A string specifying the desired foreground color.
This is passed straight to |
bg |
A string specifying the desired background color. Must be one of "bgBlack", "bgRed", "bgGreen", "bgYellow", "bgBlue" "bgMagenta", "bgCyan", or "bgWhite". By default, no background is applied. |
If color is not allowed in the terminal, the input string is returned unperturbed. If color is allowed, the input string is returned with color and background ANSI code surrounding the initial part of the string from character 1 to the character before the [ in the first pair of [].
crayon::style
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.