Day 21: devout

Welcome back for the 21st day of the #packagecalendar, today we will be taking a look at the devout package by mikefc. The devout package gives you a way to write R graphics output devices in plain R.

The package is not yet available from CRAN but can be downloaded with

remotes::install_github("coolbutuseless/devout")

For the following examples, we will use the “Last Christmas” data from earlier posts.

# remotes::install_github("PMassicotte/gtrendsR")
library(gtrendsR)
last_christmas <- gtrends("Last Christmas", time = "today 3-m")$interest_over_time

And we will be building off the chart we created back in day 11

library(ggplot2)
library(slide)
library(dplyr)
p <- last_christmas %>%
  mutate(hits_ma5 = slide_dbl(hits, ~mean(.x), .before = 4)) %>%
  ggplot(aes(date, hits)) +
  geom_point() +
  geom_line(aes(y = hits_ma5), color = "firebrick")
p

The devout package is simply delightful as it allows us to change the graphical output to anything we want. It comes with the way to set the graphical engine to ascii using the ascii() function.

library(devout)
ascii(width = 100)
p
invisible(dev.off())
##   100 O                                                          #                                  
##       ...... .............. .............. .............. .............. ............. .............
##       ...... .............. .............. .............. ........#..... ............. .............
##                                                                         #                           
##       ...... .............. .............. .............. ......#....... #............ .............
##       O                                                            XX                #      ##      
##    75 ...... .............. .............. .............. ........X..X.. .....#.......#.............
##       ...... .............. .............. .............. .......X...X.. .XX.......... ....#.XXX....
##                                                                  X # X # X X   #    # XXXX  X       
## h     ...... .............. .............. .............. .......X....X.X..X...XXX...X ...XX...#....
## i     O                                                        #X   #  X    X#X   X  X ####   #     
## t  50 ...... .............. .............. .............. ......X.....#. .##.X...##XX. .............
## s     ...... .............. .............. .............. ....#X.....#.. ..##...#..... .............
##                                                                X                                    
##       ...... .............. .............. .............. .....X........ ............. .............
##       ...... .............. .............. .............. .###X......... ............. .............
##    25 O                                                   # XX                                      
##       ...... .............. .............. ............###XX............ ............. .............
##                                                    ## XXXX                                          
##       ...... .............. ..............#.##XXXXXXXX... .............. ............. .............
##       ....XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX........... .............. ............. .............
##     0 O                                                                                             
##       ...... ............Oct.............. ............Nov.............. ...........Dec.............
##                                                   date                                              
## 

There are many other use-cases some of which can be found here.