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

remotes::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 49 animals.

The names of the animals:

sort(names(animals))
#>  [1] "alligator"    "ant"          "anxiouscat"   "bat"          "bat2"        
#>  [6] "behindcat"    "bigcat"       "buffalo"      "cat"          "chicken"     
#> [11] "chuck"        "clippy"       "cow"          "daemon"       "duck"        
#> [16] "duckling"     "egret"        "endlesshorse" "facecat"      "fish"        
#> [21] "frog"         "ghost"        "goldfish"     "grumpycat"    "hypnotoad"   
#> [26] "longcat"      "longtailcat"  "monkey"       "mushroom"     "owl"         
#> [31] "pig"          "poop"         "pumpkin"      "rabbit"       "shark"       
#> [36] "shortcat"     "signbunny"    "smallcat"     "snowman"      "spider"      
#> [41] "squirrel"     "squirrel2"    "stegosaurus"  "stretchycat"  "trilobite"   
#> [46] "turkey"       "whale"        "wolf"         "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")
#> 
#>  ----- 
#> why did the chicken cross the road 
#>  ------ 
#>     \   
#>      \
#>          _
#>        _/ }
#>       `>' \
#>       `|   \
#>        |   /'-.     .-.
#>         \'     ';`--' .'
#>          \'.    `'-./
#>           '.`-..-;`
#>             `;-..'
#>             _| _|
#>             /` /` [nosig]
#> 
say("boo!", "ghost")
#> 
#>  ----- 
#> boo! 
#>  ------ 
#>     \   
#>      \
#>      .-.
#>     (o o)
#>     | O \
#>      \   \
#>       `~~~' [nosig]
#> 
say("nope, don't do that", type = "warning")
#> 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')
#> 
#>  -------------- 
#> 2023-03-07 08:46:56 
#>  --------------
#>     \
#>       \
#>         \
#>             |\___/|
#>           ==) ^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")
#> 
#>  ----- 
#> hello world 
#>  ------ 
#>     \   ^__^ 
#>      \  (oo)\ ________ 
#>         (__)\         )\ /\ 
#>              ||------w|
#>              ||      ||

Warning

say("hello world", by = "cow", type = "warning")
#> Warning in say("hello world", by = "cow", type = "warning"): 
#>  ----- 
#> hello world 
#>  ------ 
#>     \   ^__^ 
#>      \  (oo)\ ________ 
#>         (__)\         )\ /\ 
#>              ||------w|
#>              ||      ||

String

say("hello world", by = "cow", type = "string")
#> [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 = "fortune",
    by = "rabbit",
    what_color = "#FF4500",
    by_color = "red")
#> Colors cannot be applied in this environment :( Try using a terminal or RStudio.
#> 
#>  ----- 
#> If we do that, I predict that the total amount of r-help time wasted on it will exceed the CPU time saved by orders of magnitude.
#>  Duncan Murdoch
#>  after a specialized function speeding up detection of NAs was suggested for base R
#>  R-devel
#>  April 2006 
#>  ------ 
#>     \   
#>      \
#>       ( )_( )
#>       (='.'=)
#>       (^)_(^) [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.

# make a vector of animals safe to use on windows in case vignette built on windows
not_on_windows <- c('shortcat','longcat','fish','signbunny','stretchycat',
  'anxiouscat','longtailcat','grumpycat','mushroom')
names_safe <- names(animals)[!names(animals) %in% not_on_windows]
say(what = "fortune", 
    by = sample(names_safe, 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.
#> 
#>             ------ 
#>            Andrew Thomas: ...and if something goes wrong here it is probably not WinBUGS since that has been running for more than 10 years...
#> Peter Green (from the back): ... and it still hasn't converged!
#>  Andrew Thomas and Peter Green
#>  during the talk about 'BRugs'
#>  gR 2003, Aalborg
#>  September 2003 
#>             ------ 
#>                \   
#>                 \  
#>                  \
#>      .-'          
#> '--./ /     _.---.
#> '-,  (__..-`       \
#>    \          .     |
#>     `,.__.   ,__.--/
#>      '._/_.'___.-`
say(what = "fortune", 
    by = sample(names_safe, 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.
#> 
#>  ------ 
#> I'd have called them .Rob for the current .rds file format (single object), and .Ros for the current .rda file format (>1 objects). [actually I would have called them .Rob or .Robject, and .Rwk or .Rworkspace but then I noticed that if you had a .Rob you had to have a .Ros so as not to favour one or other of the project originators :)]
#>  Barry Rowlingson
#>  in a discussion about .rda and .rds formats
#>  R-help
#>  April 2012 
#>  ------ 
#>  \   
#>   \  
#>    \
#> 
#>    .-~~^-.
#>  .'  O    \
#> (_____,    \
#>  `----.     \
#>        \     \
#>         \     \
#>          \     `.             _ _
#>           \       ~- _ _ - ~       ~ - .
#>            \                              ~-.
#>             \                                `.
#>              \    /               /           \
#>               `. |         }     |         }    \
#>                 `|        /      |        /       \
#>                  |       /       |       /          \
#>                  |      /`- _ _ _|      /.- ~ ^-.     \
#>                  |     /         |     /          `.    \
#>                  |     |         |     |             -.   ` . _ _ _ _ _ _
#>                  |_____|         |_____|                ~ . _ _ _ _ _ _ _ >

"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 = "fortune",
    by = "egret",
    what_color = bgBlue$white$italic,
    by_color = bold$green)
#> Colors cannot be applied in this environment :( Try using a terminal or RStudio.
#> 
#>  ----- 
#> A big computer, a complex algorithm and a long time does not equal science.
#>  Robert Gentleman
#>  SSC 2003, Halifax
#>  June 2003 
#>  ------ 
#>     \   
#>      \  
#>       \
#>        \   _,
#>       -==<' `
#>           ) /
#>          / (_.
#>         |  ,-,`\
#>          \\   \ \
#>           `\,  \ \
#>            ||\  \`|,
#>  jgs      _|| `=`-'
#>          ~~`~`