Skip to content

Instantly share code, notes, and snippets.

@batpigandme
Forked from romainfrancois/emojify.R
Last active July 28, 2017 16:42
Show Gist options
  • Save batpigandme/3f25b3028925c76f6c969c7310409a97 to your computer and use it in GitHub Desktop.
Save batpigandme/3f25b3028925c76f6c969c7310409a97 to your computer and use it in GitHub Desktop.
library(emo)
library(stringr)
library(purrr)
emoji_name <- emo:::emoji_name
emoji_keyword <- emo:::emoji_keyword
maybe_emoji <- function( keyword ){
if (keyword %in% names(emoji_name)) {
return(emoji_name[[keyword]])
}
# if (keyword %in% names(emoji_keyword)) {
# candidates <- emoji_keyword[[keyword]]
# name <- sample(candidates, 1)
# return(emoji_name[[name]])
# }
keyword
}
print.emojified <- function(x, ...){
cat( x )
invisible(x)
}
emojify <- function( txt ){
str_split( txt, " ")[[1]] %>%
map_chr(maybe_emoji) %>%
paste( collapse = " " ) %>%
structure( class = "emojified" )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment