top_n_emojis() returns the n most frequent emoji. By default each emoji
(unicode) appears on a single row; set duplicated = TRUE to list every name
an emoji is known by, so glyphs that share several names occupy several rows.
Usage
top_n_emojis(
data,
text,
n = 20,
duplicated = FALSE,
duplicated_unicode = lifecycle::deprecated()
)Arguments
- data
A data frame or tibble containing a text column. Grouped data frames are accepted. The verbs that work a row at a time (adding columns, or keeping and expanding rows) carry the grouping through to their result, as
dplyr::mutate()anddplyr::filter()do. The verbs that pool across rows – the counts, the co-occurrence edge lists, the time series – warn that they ignore the grouping and return one corpus-wide answer.- text
The text column to scan, supplied unquoted. Any atomic column is accepted and read as character, so a
factorworks and a numeric,Dateor logical one simply contains no emoji. A list column – or a data-frame column – is refused rather than coerced, because coercing one deparses it and the emoji found would be in the code rather than in your data. What counts as an emoji is the same in every verb; see the Detection section of tidyEmoji for the one case that surprises people, code points that are emoji only when they carryU+FE0F.- n
Number of emoji to return. Default
20.- duplicated
If
TRUE, emoji with several names occupy several rows. DefaultFALSE.- duplicated_unicode
Use
duplicatedinstead. Accepts only the values it ever meant –TRUE,FALSE,"yes"or"no"– and errors on anything else rather than reading it asFALSE, which is what"TRUE"and1used to get.
Value
A tibble with columns emoji_name, unicode, emoji_category and
n, sorted by descending n with ties broken by the glyph so the order is
deterministic – the same rule emoji_frequency() uses. When a tie
straddles position n the glyph order decides which side of the cut each
emoji falls on, and a corpus with fewer than n distinct emoji returns
every one of them rather than padding to n.
duplicated = TRUE leaves several rows sharing both n and unicode,
which that rule does not settle. Within one glyph the rows come out in
emoji_unicode_crosswalk's order for the glyph's codepoint key, and the
first of them carries the same emoji_name that duplicated = FALSE
reports. Because the join is on the key rather than on the spelling, a
glyph collects the aliases of every spelling of itself: the unqualified
U+26F9 U+200D U+2640 is listed under woman_bouncing_ball and under
the two aliases the fully-qualified spelling carries. That is what "every
name an emoji is known by" means here.
See also
emoji_frequency() for the full distribution.
Examples
df <- data.frame(text = c("\U0001f600\U0001f600\U0001f3c1", "\U0001f621"))
top_n_emojis(df, text, n = 2)
#> # A tibble: 2 × 4
#> emoji_name unicode emoji_category n
#> <chr> <chr> <chr> <int>
#> 1 grinning 😀 Smileys & Emotion 2
#> 2 checkered_flag 🏁 Flags 1