Skip to content

Instantly share code, notes, and snippets.

@romainfrancois
Created July 28, 2017 15:15
Show Gist options
  • Save romainfrancois/bd869911fb01630b55c95d8f0e5197ba to your computer and use it in GitHub Desktop.
Save romainfrancois/bd869911fb01630b55c95d8f0e5197ba 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" )
}
emojify( "Simba is a baby lion" )
emojify( "A rose by any other name would smell as sweet")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment