YouTube content frequently contains emojis, special Unicode
characters, and text in various languages. The tuber
package provides built-in functions for detecting, extracting, and
manipulating emojis without external dependencies.
Quick Start
library(tuber)
# Get comments from a video
comments <- get_all_comments(video_id = "your_video_id")
# Check which comments contain emojis
comments$has_emoji <- has_emoji(comments$text_display)
# Count emojis per comment
comments$emoji_count <- count_emojis(comments$text_display)
# Filter to emoji-rich comments
emoji_comments <- comments[comments$emoji_count > 0, ]Emoji Detection Functions
The package provides five main functions for working with emojis:
count_emojis() - Count emojis in text
count_emojis("Hello world")
#> 0
count_emojis("Rating: \U0001F600\U0001F600\U0001F600")
#> 3
count_emojis(c("None", "\U0001F44D", "\U0001F600\U0001F601"))
#> c(0, 1, 2)
extract_emojis() - Get emojis from text
extract_emojis("Hello \U0001F44B World \U0001F30D!")
#> list(c("\U0001F44B", "\U0001F30D"))
extract_emojis(c("No emoji", "\U0001F600\U0001F601"))
#> list(character(0), c("\U0001F600", "\U0001F601"))
remove_emojis() - Strip emojis from text
remove_emojis("Hello \U0001F44B World!")
#> "Hello World!"
remove_emojis(c("No emoji", "Has \U0001F600 emoji"))
#> c("No emoji", "Has emoji")
replace_emojis() - Substitute emojis
replace_emojis("Hello \U0001F44B World!", replacement = "[emoji]")
#> "Hello [emoji] World!"
replace_emojis("Rate: \U0001F600\U0001F600\U0001F600", replacement = "*")
#> "Rate: ***"Common Use Cases
Filter comments with high emoji usage
comments <- get_all_comments(video_id = "your_video_id")
comments$emoji_count <- count_emojis(comments$text_display)
# Top 10 most emoji-heavy comments
top_emoji <- comments[order(-comments$emoji_count), ][1:10, ]Text analysis without emojis
# Remove emojis for text analysis
comments$clean_text <- remove_emojis(comments$text_display)
# Now use clean_text for sentiment analysis or word cloudsEmoji frequency analysis
# Extract all emojis from comments
all_emojis <- unlist(extract_emojis(comments$text_display))
# Count frequency
emoji_freq <- table(all_emojis)
sort(emoji_freq, decreasing = TRUE)[1:10]Troubleshooting
Emojis appear as question marks
Your R environment may not support UTF-8 display. The data is still correct; only the display is affected. Try:
# Check locale
Sys.getlocale("LC_CTYPE")
# Set UTF-8 locale on macOS/Linux
Sys.setlocale("LC_CTYPE", "en_US.UTF-8")What counts as one emoji
An emoji is counted once however many code points encode it. A
family, a flag, a keycap, or a thumbs-up with a skin tone is one emoji.
tuber finds emoji per user-perceived character using the
Unicode data that ships with the stringi package, so there
is no list of emoji inside tuber to go out of date.
Text symbols such as the copyright sign, and plain digits, count as emoji only when the text presents them as one (a keycap digit, or a symbol followed by the emoji variation selector).