Skip to content

Instantly share code, notes, and snippets.

@k5cents
Created November 11, 2019 21:42
Show Gist options
  • Save k5cents/848cd5cdc0d8de4872ebbb7fbd0e2dfd to your computer and use it in GitHub Desktop.
Save k5cents/848cd5cdc0d8de4872ebbb7fbd0e2dfd to your computer and use it in GitHub Desktop.
Code to replace emoji with markdown short code
library(jsonlite)
library(tidyverse)
library(magrittr)
url <- "https://gist.githubusercontent.com/oliveratgithub/0bf11a9aff0d6da7b46f1490f86a71eb/raw/ac8dde8a374066bcbcf44a8296fc0522c7392244/emojis.json"
shortcodes <-
fromJSON(url) %>%
use_series("emojis") %>%
as_tibble() %>%
na_if("") %>%
arrange(as.numeric(order)) %>%
select(emoji, shortname) %>%
filter(!is.na(shortname))
head(shortcodes)
ex <- "I'm so cool 😎 I can code!"
str_replace_all(ex, pattern = deframe(shortcodes))
@k5cents
Copy link
Author

k5cents commented Nov 11, 2019

Error in stri_replace_all_regex(string, pattern, fix_replacement(replacement),  : 
  Syntax error in regexp pattern. (U_REGEX_RULE_SYNTAX)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment