Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R - Emoji unicode to character

I'm coding in R. Let's say that I have the unicode value of an emoji as

wink_emoji <- "\U0001f609"

Or, alternatively, as

wink_emoji <- "U+1f609"

Is there a function that I can use to print the actual emoji character to the console? Like this:

[1] "😉"

How about as its HTML character entity?

[1] "&#128521;"

Furthermore, if I have a string like so:

test <- "This is a test U+1f609 U+1F469 U+200D U+2764 U+FE0F U+200D U+1F48B U+200D U+1F469"

Can I run it through a function to match all of the emojis and return this:

[1] "This is a test 😉👩‍❤️‍💋‍👩"
like image 994
Christopher Costello Avatar asked Oct 20 '25 04:10

Christopher Costello


1 Answers

Use utf8_print from the utf8 package to print, utf8ToInt to get the integer value of the code point:

wink_emoji <- "\U0001f609"
utf8::utf8_print(wink_emoji)
#> [1] "😉​"
utf8ToInt(wink_emoji)
#> [1] 128521

(Printing emoji only works on MacOS and Linux, not on Windows.)

like image 133
Patrick Perry Avatar answered Oct 21 '25 17:10

Patrick Perry