Last active
November 23, 2018 19:16
-
-
Save mine-cetinkaya-rundel/edab209c6831bae18ce1ff5bf271f679 to your computer and use it in GitHub Desktop.
Extracting emojis for each lesson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Lesson emojis" | |
author: "Mine Çetinkaya-Rundel" | |
date: "11/21/2018" | |
output: | |
html_document: | |
highlight: pygments | |
theme: cerulean | |
--- | |
Start by loading packages. | |
```{r message=FALSE} | |
library(fs) | |
library(tidyverse) | |
library(emo) | |
library(here) | |
library(glue) | |
library(knitr) | |
``` | |
Use **fs** to get a list of all `Rmd` files in the subfolders of the | |
`static/slides` folder. | |
```{r} | |
files <- fs::dir_info(here("static", "slides"), recursive = TRUE, glob = "*.Rmd") %>% | |
slice(-1) %>% | |
mutate(path = as.character(path)) %>% | |
select(path) | |
``` | |
Define two functions for extracting the title and emoji keyword from the second | |
line of each Rmd file. This is the line that contains the `title` in the YAML. | |
```{r} | |
extract_title <- function(x){ | |
read_lines(as.character(x), skip = 1, n_max = 1) %>% | |
str_extract(" .*\\<") %>% | |
str_remove('\"') %>% | |
str_remove("\\<") %>% | |
str_trim() | |
} | |
extract_keyword <- function(x){ | |
read_lines(as.character(x), skip = 1, n_max = 1) %>% | |
str_extract("emo::ji\\(.*\\)") %>% | |
str_remove("emo::ji\\('") %>% | |
str_remove("'\\)") | |
} | |
``` | |
Grab titles, keywords, and find corresponding emojis, with a little bit of | |
help from [here](https://github.com/hadley/emo/blob/master/README.Rmd). | |
```{r results='asis'} | |
files <- files %>% | |
mutate( | |
title = map_chr(path, extract_title), | |
keyword = map_chr(path, extract_keyword), | |
emoji = map_chr(keyword, function(x) glue(emo::ji_name[x], collapse = "")) | |
) | |
``` | |
View titles, keywords, and emojis. | |
```{r} | |
files %>% | |
select(title, emoji, keyword) %>% | |
kable() | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment