glue (version 1.4.2)

glue_col: Construct strings with color

Description

The crayon package defines a number of functions used to color terminal output. glue_col() and glue_data_col() functions provide additional syntax to make using these functions in glue strings easier.

Using the following syntax will apply the function crayon::blue() to the text 'foo bar'.

{blue foo bar}

If you want an expression to be evaluated, simply place that in a normal brace expression (these can be nested).

{blue 1 + 1 = {1 + 1}}

Usage

glue_col(..., .envir = parent.frame(), .na = "NA")

glue_data_col(.x, ..., .envir = parent.frame(), .na = "NA")

Arguments

...

[expressions] Unnamed arguments are taken to be expressions string(s) to format. Multiple inputs are concatenated together before formatting. Named arguments are taken to be temporary variables available for substitution.

.envir

[environment: parent.frame()] Environment to evaluate each expression in. Expressions are evaluated from left to right. If .x is an environment, the expressions are evaluated in that environment and .envir is ignored. If NULL is passed it is equivalent to emptyenv().

.na

[character(1): ‘NA’] Value to replace NA values with. If NULL missing values are propagated, that is an NA result will cause NA output. Otherwise the value is replaced by the value of .na.

.x

[listish] An environment, list or data frame used to lookup values.

Examples

Run this code
# NOT RUN {
if (require(crayon)) {
  glue_col("{blue foo bar}")

  glue_col("{blue 1 + 1 = {1 + 1}}")

  white_on_grey <- bgBlack $ white
  glue_col("{white_on_grey
    Roses are {red {colors()[[552]]}}
    Violets are {blue {colors()[[26]]}}
    `glue_col()` can show {red c}{yellow o}{green l}{cyan o}{blue r}{magenta s}
    and {bold bold} and {underline underline} too!
    }")
}
# }

Run the code above in your browser using DataLab