在我昨天的问题中,"Can R read html-encoded emoji characters?" ,用户rensa noted that :
As far as I'm aware, there's no solution to printing emoji in the R console: they always come out as "U0001f600" (or what have you). However, the packages I described above can help you plot emoji in some circumstances (I'm hoping to expand ggflags to display arbitrary full-colour emoji at some point). They can also help you search for emoji to get their codes, but they can't get names given the codes AFAIK. But maybe you could try importing the emoji list from emojilib into R and doing a join with your data frame, if you've extracted the emoji codes into a column, to get the English names.
这在 R 中看起来怎么样?
(注意:我发布这个问题的目的是立即回答它,而不是在上面链接的问题中发布这个问题,因为它与该问题无关,但仍然可能对其他人有用。)
最佳答案
下面的方法适用于将表情符号字符或 unicode 表示形式转换为名称。
我很高兴在 CC0 贡献下发布下面的代码片段(即,将此实现放入公共(public)领域以供免费重用)。
# Get (MIT-licensed) emojilib data:
emoji_json_file <- "https://raw.githubusercontent.com/muan/emojilib/master/emojis.json"
json_data <- rjson::fromJSON(paste(readLines(emoji_json_file), collapse = ""))
get_name_from_emoji <- function(emoji_unicode, emoji_data = json_data){
emoji_evaluated <- stringi::stri_unescape_unicode(emoji_unicode)
# names(json_data)
vector_of_emoji_names_and_characters <- unlist(
lapply(json_data, function(x){
x$char
})
)
name_of_emoji <- attr(
which(vector_of_emoji_names_and_characters == emoji_evaluated)[1],
"names"
)
name_of_emoji
}
get_name_from_emoji("\\U0001f917")
# [1] "hugs"
get_name_from_emoji("🤗") # An attempt actually pasting the hugs emoji in also works.
# [1] "hugs"
关于r - R 可以将表情符号字符转换为对应的文本吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48154928/