multi_color: Multi-color text

Description Usage Arguments Details Value Examples

View source: R/multi_color.R

Description

Multi-color text

Usage

1
2
3
4
5
6
7
8
9
multi_color(
  txt = "hello world!",
  colors = "rainbow",
  type = "message",
  direction = "vertical",
  recycle_chars = FALSE,
  add_leading_newline = FALSE,
  ...
)

Arguments

txt

(character) Some text to color. cowsay animals are available in a list of multicolor::things, e.g. things$cow.

colors

(character) A vector of colors, defaulting to "rainbow", i.e. c("red", "orange", "yellow", "green", "blue", "purple").

Several out-of-the-box palettes are available; see multicolor::palettes.

Must all be crayon-supported colors. Any colors in colors() or hex values (see ?rgb) are fair game.

type

(character) "message" (the default), "warning", "string", or "rmd". If "rmd" is used, the type of the RMarkdown document should be html_document the chunk option results = "asis" should be used.

direction

(character) How should the colors be spread? One of "horizontal" or "vertical".

recycle_chars

(logical) Should the vector of colors supplied apply to the entire string or should it apply to each individual character (if direction is vertical) or line (if direction is horizontal), and be recycled?

add_leading_newline

Should a newline be added at the beginning of the text? Useful for cowsay animals when type = "rmd".

...

Further args.

Details

This function evenly (ish) divides up your string into these colors in the order they appear in colors.

It cannot be used with RGUI (R.app on some systems).

Value

A string if type is "string", or colored text if type is "message" or "warning"

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
## Not run: 
multi_color()

multi_color("ahoy")

multi_color(
  "taste the rainbow",
  c("rainbow", "cyan", "cyan", "rainbow")
)
multi_color(
  "taste the rainbow",
  c(
    "mediumpurple",
    "rainbow",
    "cyan3"
  )
)

multi_color(colors = c(
  rgb(0.1, 0.2, 0.5),
  "yellow",
  rgb(0.2, 0.9, 0.1)
))

multi_color(
  things$buffalo,
  c("mediumorchid4", "dodgerblue1", "lemonchiffon1")
)

# Built-in color palette
multi_color(things$cow, colors = palettes$lacroix)

multi_color(cowsay:::rms, sample(colors(), 10))

# Mystery Bulgarian animal
multi_color(things[[sample(length(things), 1)]],
  c("white", "darkgreen", "darkred"),
  direction = "horizontal"
)

# Mystery Italian animal
multi_color(things[[sample(length(things), 1)]],
  c("darkgreen", "white", "darkred"),
  direction = "vertical"
)

## End(Not run)

multicolor documentation built on Nov. 4, 2021, 5:06 p.m.