Using Emojis in R and R Markdown

Recently I worked on some pull requests for interactive tutorials for the OpenIntro textbook Introduction to Modern Statistics. There I came across the package emo. Its purpose is: “Easily insert emoji into and RMarkdown”.

I was surprised that there is a special package. I didn’t think that including emojis wouldn’t be a problem – at least on the macOS. I only have to open the window for emojis and symbols (CMD-SHIFT-SPACE) and double click on the icon to insert it into the markdown document. No big deal, so what’s the matter?

Screenshot of macOS window showing a selection of emojis

After I searched online, I saw that there many questions (and solutions) about this problem. There is on CRAN a special package emojifont for using emojis and Font Awesome in base R and ggplot2 graphics and with emoGG another one on GitHub.

For me, it is still not clear what exactly the problem is. Perhaps it has to do with different operating systems? Does the Unicode not translate to all systems?

Anyway, I looked into emo, and it turned out that it offers some useful functions when working with strings containing emojis. You can also add emojis to summarize p-values. Additionally, I learned several things:

  1. With emojis_df <- emo::jis, you get a data frame with 3570 emoticons categorized by 21 variables.

  2. In emojis_df, you will find the keywords for each emoji. But this is problematic as they are not unique. In the ReadMe of emo in GitHub, you will see a massive list of multiple references for each keyword.

  3. If you are using keywords, the command emo::ji(<keyword>) will randomly pick one.

emo::ji("face")
emo::ji("face")
emo::ji("face")
## 😈
## 💆 
## 👼 

To identify, you have to use the short name of the Common Local Data Repository (CDLR) included in the emojis_df. If you want to use emojis with a particular skin tone, you have to use the alias name as the CDLR name produces an error. Instead of looking up an emoji within the above-created data frame emojis_df, I found it more practicable to search in the official Unicode Emoji List. It has not so many different columns but focuses on icon display and CLDR short name.

Edit this page

Peter Baumgartner
Peter Baumgartner
Retired Professor of Technology Enhanced Learning (TEL)

My research interests include eLearning, educational technology, educational design, open science and data science education.


Related