Happy World Emoji Day: an analysis of rOpenSci's Slack emojis

HAPPY world emoji day! 🌍 πŸ” πŸ“†

In honor of this momentous occasion, I have decided to analyze the emojis used on rOpenSci’s Slack.

library("dplyr")

If you’d like to follow along, go fetch yourself a Slack token.

token <- "MY_SLACK_API_TOKEN" ## stick your token here

We will first use Slack’s reactions.list method.

Notice here I am pulling the items from the response and then from each item I am interested in the message reactions. This ignores the reactions on files and comments.

req_lst <- httr::POST(
  "https://slack.com/api/reactions.list",
  body = list(
   token = token,
   count = 500
   )) %>%
  httr::content() %>%
  .$items %>%
  purrr::map(~.[["message"]][["reactions"]])

Let’s pull out the name and count of each emoji used and stick it in a tibble πŸŽ‰.

tbl <- tibble::tibble(
  name = purrr::map_chr(purrr::flatten(req_lst), "name"),
  count = purrr::map_int(purrr::flatten(req_lst), "count")
)

One of the most delightful features in Slack is the ability to create custom emojis! In order to be able to display both ordinary and custom emojis, I can pull in a list of all emojis we have customized in the rOpenSci Slack team using the emoji.list method.

Notice here I am using the tibble::enframe() function. This is an awesome way to convert a vector or list to a two-column data frame.

emojis_tbl <- httr::POST(
  "https://slack.com/api/emoji.list",
  body = list(token = token)
  ) %>%
  httr::content() %>%
  .$emoji %>%
  tibble::enframe() %>%
  mutate(value = unlist(value))

The emojis_tbl data frame contains the name of each custom emoji and a link to their associated image. Here I create a small function that will either read that image using the magick package or, if it is an ordinary emoji, use the emo package to look it up.

read_emoji <- function(x, y) {
  if (!is.na(x)) {
    magick::image_read(x)
  } else {
    emo::ji(y)
  }
}

Let’s do a wee bit of data wrangling 🚜 to sort out which emojis are used the most.

top_emojis <- tbl %>%
  group_by(name) %>%
  summarise(count = sum(count)) %>%
  arrange(desc(count)) %>%
  slice(1:10) %>%
  left_join(emojis_tbl, by = "name") %>%
  mutate(emoji = purrr::map2(value, name, read_emoji))

I have written another small function to make sure the custom emojis print properly when I render my output.

Note, if you are doing this for your blog, rather than saving a temporary file as I have demonstrated here, you should save this as a relative file path in your blog 🌳 .

render_emoji <- function(x, y) {
  if (inherits(x, "magick-image")) {
    tmp <- tempfile(fileext = ".gif")
    x <- magick::image_scale(x, "25x25")
    magick::image_write(x, path = tmp)
    emoji <- rep(glue::glue("![]({tmp})"), as.integer(y/7))
    print(glue::glue("{glue::collapse(emoji)}: {y}\n\n"))
  } else {
    emoji <- rep(x, as.integer(y/7))
    print(glue::glue("{glue::collapse(emoji)}: {y}\n\n"))
  }
}

Now let’s walk it out πŸ’ƒ.

purrr::walk2(top_emojis$emoji, top_emojis$count, render_emoji)

πŸ‘‹πŸ‘‹πŸ‘‹πŸ‘‹πŸ‘‹πŸ‘‹πŸ‘‹πŸ‘‹πŸ‘‹πŸ‘‹πŸ‘‹πŸ‘‹πŸ‘‹πŸ‘‹πŸ‘‹πŸ‘‹πŸ‘‹πŸ‘‹: 130

πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘: 129

❀️❀️❀️❀️❀️❀️❀️❀️❀️❀️❀️: 83

: 75

πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰: 65

πŸ“πŸ“πŸ“πŸ“πŸ“: 36

πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚: 34

βž•βž•βž•βž•: 29

🍻🍻🍻🍻: 28

: 27

How delightful! It is no surprise that the πŸ‘‹ is the most popular emoji used, since rOpenSci is an extraordinarily welcoming crew! In fact the community organizer, Stefanie, just wrote a blog post about our Slack #welcome channel. I am (obviously) very proud to see that πŸ“ makes a strong appearance (#rchickenladies), and of course delighted to see our Aussie friends getting represented by the Aussie party parrot.


Lucy D'Agostino McGowan image
Lucy D'Agostino McGowan

Currently excited about: observational study methods, translational research, BB-8

comments powered by Disqus