Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Everybody knows the Simpsons, everybody loves the Simpsons and everybody can laugh about Bart Simpson writing funny lines on the blackboard! If you want to create your own Bart Simpson Blackboard Meme Generator with R read on!
Conveniently enough there is a package for creating memes already (who would have thought otherwise, because there is a package for everything!), the meme
package by my colleague Professor Guangchuang Yu from the University of Hong Kong. After installing it from CRAN we load it, assuming that you work on a Windows machine load the Comic Sans and a clean Bart Simpson Blackboard pic into R:
library(meme) if (.Platform$OS.type == "windows") { windowsFonts(Comic = windowsFont("Comic Sans MS")) } bart <- "pics/bart_simpson_chalkboard-5157.gif" # source: http://free-extras.com/images/bart_simpson_chalkboard-5157.htm
We can start right away by using the meme
function with the pic, text, size and as arguments (for a new line use the "\n"
escape sequence):
meme(bart, "\nfor (i in 1:100) {\n print(\"I will not use loops in R\")\n}", size = 1.8, = "Comic", vjust = 0, r = 0)
As an aside: to fully appreciate the joke you should know something about loops and how to avoid them by making use of vectorization in R (see here: Learning R: The Ultimate Introduction (incl. Machine Learning!). Another method to avoid loops is by using the apply family of functions (for those so-called higher-order functions see here: Learning R: A Gentle Introduction to Higher-Order Functions).
But if you want to go full “Bart Simpson” you, of course, need to repeat the lines several times (the rep
function comes in handy here). The whole (punitive) work is done by this short piece of code (just change text
for your own memes):
text <- "I will not waste chalk" text <- paste(rep(text, 8), collapse = "\n") text <- paste0("\n", text) meme(bart, text, size = 1.6, = "Comic", vjust = 0, r = 0)
Happy memeing with BaRt!
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.