cowsay makes it easy to print messages, warnings, or character strings with various animals and other creatures.

Installation

Stable version from CRAN

install.packages("cowsay")

or dev version from GitHub

install.packages("devtools")
devtools::install_github("sckott/cowsay")
library(cowsay)

The animals

The animals, and other ascii creatures, are all in a single named character vector that is exported from the package. Thus, you can access each animal yourself, and do whatever you want with it.

As of this writing, there are 41 animals.

The names of the animals:

sort(names(animals))
#>  [1] "ant"          "anxiouscat"   "bat"          "bat2"        
#>  [5] "behindcat"    "bigcat"       "buffalo"      "cat"         
#>  [9] "chicken"      "clippy"       "cow"          "daemon"      
#> [13] "duck"         "duckling"     "egret"        "endlesshorse"
#> [17] "facecat"      "fish"         "frog"         "ghost"       
#> [21] "grumpycat"    "hypnotoad"    "longcat"      "longtailcat" 
#> [25] "monkey"       "mushroom"     "owl"          "pig"         
#> [29] "poop"         "pumpkin"      "rabbit"       "shark"       
#> [33] "shortcat"     "signbunny"    "smallcat"     "snowman"     
#> [37] "spider"       "stretchycat"  "trilobite"    "turkey"      
#> [41] "yoda"

For example, access the cow

cow <- animals[['cow']]
cat(cow)
#> 
#>  ----- 
#> %s 
#>  ------ 
#>     \   ^__^ 
#>      \  (oo)\ ________ 
#>         (__)\         )\ /\ 
#>              ||------w|
#>              ||      ||

Say something

We expose the function say() in this package, which you can use to envoke any animal in the package, and make it say whatever you want. Some examples:

say("why did the chicken cross the road", "chicken")
#> Colors cannot be applied in this environment :( Try using a terminal or RStudio.
#> 
#> 
#>  ----- 
#> why did the chicken cross the road 
#>  ------ 
#>     \   
#>      \
#>          _
#>        _/ }
#>       `>' \
#>       `|   \
#>        |   /'-.     .-.
#>         \'     ';`--' .'
#>          \'.    `'-./
#>           '.`-..-;`
#>             `;-..'
#>             _| _|
#>             /` /` [nosig]
#> 
say("boo!", "ghost")
#> Colors cannot be applied in this environment :( Try using a terminal or RStudio.
#> 
#> 
#>  ----- 
#> boo! 
#>  ------ 
#>     \   
#>      \
#>      .-.
#>     (o o)
#>     | O \
#>      \   \
#>       `~~~' [nosig]
#> 
say("nope, don't do that", type = "warning")
#> Colors cannot be applied in this environment :( Try using a terminal or RStudio.
#> Warning in say("nope, don't do that", type = "warning"): 
#>  -------------- 
#> nope, don't do that 
#>  --------------
#>     \
#>       \
#>         \
#>             |\___/|
#>           ==) ^Y^ (==
#>             \  ^  /
#>              )=*=(
#>             /     \
#>             |     |
#>            /| | | |\
#>            \| | |_|/\
#>       jgs  //_// ___/
#>                \_)
#> 

There’s the special time, that will print out the time

say('time')
#> Colors cannot be applied in this environment :( Try using a terminal or RStudio.
#> 
#>  -------------- 
#> 2018-09-17 15:57:12 
#>  --------------
#>     \
#>       \
#>         \
#>             |\___/|
#>           ==) ^Y^ (==
#>             \  ^  /
#>              )=*=(
#>             /     \
#>             |     |
#>            /| | | |\
#>            \| | |_|/\
#>       jgs  //_// ___/
#>                \_)
#> 

It’s how you say it

You can use say() and give back a string, message, or warning

Message

say("hello world", by = "cow")
#> Colors cannot be applied in this environment :( Try using a terminal or RStudio.
#> 
#>  ----- 
#> hello world 
#>  ------ 
#>     \   ^__^ 
#>      \  (oo)\ ________ 
#>         (__)\         )\ /\ 
#>              ||------w|
#>              ||      ||

Warning

say("hello world", by = "cow", type = "warning")
#> Colors cannot be applied in this environment :( Try using a terminal or RStudio.
#> Warning in say("hello world", by = "cow", type = "warning"): 
#>  ----- 
#> hello world 
#>  ------ 
#>     \   ^__^ 
#>      \  (oo)\ ________ 
#>         (__)\         )\ /\ 
#>              ||------w|
#>              ||      ||

String

say("hello world", by = "cow", type = "string")
#> Colors cannot be applied in this environment :( Try using a terminal or RStudio.
#> [1] "\n ----- \nhello world \n ------ \n    \\   ^__^ \n     \\  (oo)\\ ________ \n        (__)\\         )\\ /\\ \n             ||------w|\n             ||      ||"

Add color

library(jsonlite)
library(multicolor)

We rely on the crayon package for color and the multicolor package for multiple colors. The arguments you supply to what_color and by_color can be strings – either the color name or a hex value – or a function of class crayon.

say(what = "holygrail",
    by = "rabbit",
    what_color = "#FF4500",
    by_color = "red")
#> Colors cannot be applied in this environment :( Try using a terminal or RStudio.
#> 
#> 
#>  ----- 
#> She looks like one. 
#>  ------ 
#>     \   
#>      \
#>       ( )_( )
#>       (='.'=)
#>       (^)_(^) [nosig]
#> 

colors() are all supported as are any rgb values that evaluate to a string. Supplying multiple colors for what_color or by_color is allowed, as long as they’re in a character vector. “rainbow” is also allowed.

say(what = "arresteddevelopment", 
    by = sample(names(animals), 1),
    what_color = rgb(.1, .2, .3),
    by_color = sample(colors(), 5),
    type = "message")
#> Colors cannot be applied in this environment :( Try using a terminal or RStudio.
#> 
#>  ----- 
#> Steve Holt! 
#>  ------ 
#>     \   
#>      \  
#>       \
#>        \   _,
#>       -==<' `
#>           ) /
#>          / (_.
#>         |  ,-,`\
#>          \\   \ \
#>           `\,  \ \
#>            ||\  \`|,
#>  jgs      _|| `=`-'
#>          ~~`~`
say(what = "arresteddevelopment", 
    by = sample(names(animals), 1),
    what_color = rgb(.1, .2, .3),
    by_color = sample(colors(), 5),
    type = "message")
#> Colors cannot be applied in this environment :( Try using a terminal or RStudio.
#> 
#> 
#>  ----- 
#> Michael! 
#>  ------ 
#>     \   
#>      \  
#>       \
#>        ,
#>     _,,)\.~,,._
#>      (()`  ``)\))),,_
#>       |     \ ''((\)))),,_          ____
#>       |6`   |   ''((\())) "-.____.-"    `-.-,
#>       |    .'\    ''))))'                  \)))
#>       |   |   `.     ''                     ((((
#>       \, _)     \/                          |))))
#>        `'        |                          (((((
#>                  \                  |       ))))))
#>                   `|    |           ,\     /((((((
#>                    |   / `-.______.<  \   |  )))))
#>                    |   |  /         `. \  \  ((((
#>                    |  / \ |           `.\  | (((
#>                    \  | | |             )| |  ))
#>                     | | | |             || |  '   [endless.horse]
#>                     | | | |             || |

"rainbow" is the same as c("red", "orange", "yellow", "green", "blue", "purple"). Saves you a bit of typing.

say(what = "foobar",
    by = "shark",
    what_color = "rainbow",
    by_color = c("rainbow", "rainbow", "rainbow"))
#> Colors cannot be applied in this environment :( Try using a terminal or RStudio.
#> 
#>     
#>  -------------- 
#> foobar 
#>  --------------
#>     \
#>       \
#>         \
#>               /""-._
#>               .       '-,
#>                :          '',
#>                 ;      *     '.
#>                  ' *         () '.
#>                    \               \
#>                     \      _.---.._ '.
#>                     :  .' _.--''-''  \ ,'
#>         .._           '/.'             . ;
#>         ; `-.          ,                \'
#>          ;   `,         ;              ._\
#>           ;    \     _,-'                ''--._
#>           :    \_,-'                          '-._
#>           \ ,-'                       .          '-._
#>           .'         __.-'';            \...,__       '.
#>         .'      _,-'        \              \   ''--.,__  '\
#>         /    _,--' ;         \              ;           \^.}
#>         ;_,-' )     \  )\      )            ;
#>              /       \/  \_.,-'             ;
#>             /                              ;
#>          ,-'  _,-'''-.    ,-.,            ;      PFA
#>       ,-' _.-'        \  /    |/'-._...--'
#>      :--``             )/
#>   '
#> 

The main advantage of using crayon functions instead of color strings is the ability to combine styles together.

library(crayon)

say(what = "simpsons",
    by = "egret",
    what_color = bgBlue$white$italic,
    by_color = bold$green)
#> Colors cannot be applied in this environment :( Try using a terminal or RStudio.
#> 
#>  ----- 
#> I didn't get rich by signing checks. 
#>  ------ 
#>     \   
#>      \  
#>       \
#>        \   _,
#>       -==<' `
#>           ) /
#>          / (_.
#>         |  ,-,`\
#>          \\   \ \
#>           `\,  \ \
#>            ||\  \`|,
#>  jgs      _|| `=`-'
#>          ~~`~`