Skip to contents

A tidy toolkit for working with the emoji in any text column, such as social-media posts, product reviews, chat logs or survey responses. Unicode is awkward to handle and not every code point is an emoji, which makes emoji statistics fiddly to obtain. 'tidyEmoji' extracts, counts, categorises, sentiment-scores and emotion-scores emoji, converts them to and from text (for accessibility and NLP preprocessing), searches the emoji catalogue, maps emoji co-occurrence and sequences (graph-ready edge lists and n-grams), measures where and how densely emoji are used, and builds document-by-emoji feature tables for machine learning, with grapheme-aware detection (so skin-tone and multi-person sequences stay intact), returning tidy data frames that slot straight into a 'tidyverse' workflow. It also quantifies how much annotators disagreed about an emoji (interpretation risk), extracts the words around each emoji, tracks emoji use over time, measures text-emoji sentiment mismatch, and applies explicit emoji-preprocessing policies for language-model pipelines. Its emoji catalogue is the Unicode emoji test data, bundled and current to Emoji 18.0, so it can also say what a glyph is, map flag emoji to ISO 3166 codes, report how much of a corpus each lexicon can score, and read reaction tallies as well as text. It reads what an emoji depicts (skin tone, gender, hair) to describe glyph use and to rewrite tones for counterfactual experiments, reports runs of emoji and the facts behind their accessibility, and finds, decodes and removes hidden payloads, invisible characters that carry a message to a language model. Its keywords unite those of the 'emoji' package with the annotations in release 49 of the Unicode Common Locale Data Repository, and the shortcodes of the newest emoji come from 'emojibase' (MIT). The bundled emoji sentiment lexicon is from the Emoji Sentiment Ranking of Kralj Novak et al. (2015) doi:10.1371/journal.pone.0144296 , released under CC BY-SA 4.0; the emotion lexicon is from EmoTag1200 of Shoeb & de Melo (2020) https://aclanthology.org/2020.emnlp-main.720/, released under the MIT licence. The example data, dated and multilingual, is a sample of 'OpenAssistant' Conversations (Kopf et al., 2023) doi:10.48550/arXiv.2304.07327 , released under the Apache License 2.0.

Output and naming contract

Every verb follows verb(data, text, ...), takes the text column unquoted, and returns a tibble. Output column names come in three shapes, and which one you get tells you what the column is:

  • .emoji_* – a measurement of your text, added to your data (.emoji, .emoji_name, .emoji_category, .emoji_sentiment, .emoji_n, ...). Dotted so it will not collide with your own columns.

  • .row_number, .position, .period, .period_prev, .period_label – structural indices saying where a row came from rather than what was measured: the position of the entry in data (emoji_extract_unnest(), emoji_context(), emoji_ngrams(), emoji_dfm()), where in that entry something sits, or the time bucket (emoji_trend(), emoji_turnover(), emoji_seasonality()). Dotted for the same reason, and reserved on the same terms. That is the whole list.

    .position is the one of the five whose unit depends on the verb, so it is worth reading before you index with it. In emoji_context() it is a code-point offset into the text, the unit substr() takes, so substr(text, .position, .position + nchar(.emoji) - 1) returns the glyph. In emoji_ngrams() it is the index within the row's emoji sequence, so the first n-gram of a row is 1 whatever the text looks like. Both pages say which, and the two are not interchangeable.

  • bare names – the columns of a new summary tibble, which is not your data with something added (emoji_frequency()'s emoji, name, n; emoji_ambiguity()'s ambiguity, rank). emoji_dfm() is the one verb whose column names are data: one per emoji, named with the glyph itself.

Every dotted name is reserved: a verb overwrites any column of its own output name that is already there, without warning. That is what makes verbs chainable and re-runnable – emoji_sentiment() then emoji_position() both write .emoji_n, and both mean the same thing – but it also means a column of your own called .emoji_n will be replaced, and that includes the text column itself if you named it .emoji_n. Rename it first if you need to keep it.

Two of the shared dotted names do not mean the same thing in every verb that writes them, so chaining those verbs replaces a number with a different one rather than with the same one:

So emoji_sentiment() followed by emoji_emotion() leaves a .emoji_n_scored describing the emotion lexicon beside a .emoji_sentiment that does not. Rename the first result's column before adding the second, or keep the two tables apart.

group always refers to the Unicode top-level category (the term used by Unicode's own emoji-test.txt, which the catalogue is built from). Every glyph-to-metadata join is normalised through a codepoint key that strips the U+FE0F variation selector, so qualified and unqualified emoji forms resolve identically in every verb.

Rates and their denominators

Every rate tidyEmoji returns ships with the numerator and the denominator it was computed from, so a user can fit a count model (a Poisson or negative binomial regression of the count with the denominator as its exposure) instead of a linear model on a ratio. emoji_ratio() returns .emoji_codepoints and .emoji_n_char beside .emoji_ratio, emoji_density() returns .emoji_n_char and .emoji_n_token beside its two densities, emoji_trend() returns n_period beside share, and emoji_coverage() returns the counts beside both coverages. Where a table already carries every count a share is built from, as emoji_seasonality() and emoji_version_profile() do, the denominator is the column's total.

This matters more than it sounds. Emoji counts are compositional (shares of a document's total) and heavily zero-inflated, and the log-ratio transforms compositional analysis depends on are undefined at zero, so a bare quotient pushes the analyst into the modelling error. tidyEmoji offers no clr or ilr transform, because zero replacement is a methodological choice that belongs to the analysis (compositions and zCompositions make it properly), but it returns what such a choice needs. A new verb is held to the same rule.

Detection

Detection is grapheme-aware: a skin-tone modifier or a zero-width-joiner sequence (a family, a couple, a profession) stays intact as one emoji, and every verb asks the same question, so counts agree across the package.

What counts as an emoji is decided by the catalogue, Unicode's own emoji-test.txt for the version emoji_unicode_version() reports, bundled with the package. emoji_properties() shows what it records about any glyph. Until 0.6.0 the catalogue was the table inside the emoji package, which stayed at Emoji 16.0 through two Unicode releases, so the 182 emoji added in 17.0 and 18.0 were invisible; they are detected now. A corpus re-run under 0.6.0 can therefore report more emoji than it did, and because of the two repairs below, it can also report fewer.

There is one systematic exclusion, and it is worth knowing before you read a count. Some code points are emoji only in their emoji-presentation form, that is only when the variation selector U+FE0F is present. The best-known is the heart: U+2764 U+FE0F is detected, the bare U+2764 is not, and several keyboards emit the bare form. Across the catalogue 1272 spellings carry U+FE0F, and 216 of those become undetectable if it is dropped: in the bundled sentiment lexicon, 57 of the scorable glyphs. Counted the other way round, 212 of the catalogue's 5244 spellings are themselves undetectable; the two figures measure different things and both are right.

The selector does not always go at the end. For 200 of those 212 it does, so appending U+FE0F is what makes them detectable. The exceptions are the 12 keycap sequences – #, * and 0 to 9 followed by the enclosing keycap mark U+20E3 – where the selector belongs between the two: U+0031 U+FE0F U+20E3 is detected and U+0031 U+20E3 U+FE0F is not. Inserting U+FE0F after the first code point is the rule that repairs all 212.

presentation = "any" reads them as they are, on every verb that counts, scores or rewrites emoji, without your having to repair the text: all 212 except three. The default does not, and that is deliberate rather than an oversight: the same set contains U+00A9, U+00AE and U+2122, so matching them would count the copyright sign in a legal footer as emoji use, which is why "any" leaves those three out. The default stays "emoji", because widening it would silently recount every corpus already analysed; emoji_coverage() reports what the choice adds. Detection is the only thing affected; the join is not. Every glyph-to-metadata lookup strips U+FE0F first, so if you hand a bare U+2764 to as_emoji_name(), emoji_sentiment()'s lexicon or emoji_ambiguity(), it resolves exactly like the qualified form.

Joined sequences are unaffected either way. Unicode lists several spellings of a zero-width-joiner sequence – fully qualified, and shorter forms with the selectors omitted – and a shorter one can leave an undetectable component in the middle. Detection repairs those: every fully-qualified and minimally-qualified spelling in the catalogue is read as exactly one emoji, so U+2764 U+200D U+1F525 is "heart on fire" rather than "fire" even with its selectors stripped.

Two things are emoji material without being emoji, and since 0.6.0 no verb counts them:

  • A skin-tone swatch or hair component standing alone. A modifier applied to a base that cannot take one, as in U+1F600 U+1F3FB, leaves the swatch with nothing to modify. That is one emoji, the grinning face, and a swatch; until 0.6.0 it was counted as two emoji, the second named "light skin tone" in group "Component".

  • Regional indicators that spell no flag. Any two regional indicators form one grapheme cluster, so U+1F1FD U+1F1FD ("XX") used to be read as an emoji with no name, as did a lone indicator. Only 259 of the 676 possible pairs are flags in the catalogue; anything else is not an emoji. Subdivision flags are tag sequences, not pairs, and are unaffected.

Neither is silently discarded. emoji_summary() counts both, in n_orphan_components and n_invalid_flags, so a corpus whose count fell can be explained, and emoji_country() reports a stray pair with its glyph and no country code. The verbs that rewrite text treat them as before 0.6.0 (emoji_sanitize(policy = "strip") still removes a swatch, and emoji_to_text() still names it), because what changed is what is counted, and a swatch left in a stripped column would still be a swatch.

Since 0.7.0 the catalogue decides two more cases, and what a reader sees decides how a sequence splits:

  • A symbol with a stray U+FE0F is an emoji only if the catalogue lists it. The detection regex, inherited from the emoji package, accepts any pictographic code point followed by U+FE0F, a presentation sequence Unicode defines for only some of them, so a black star (U+2605), a chess piece or a playing card with a selector after it came back as an emoji with no name: 1,111 code points in all. No verb counts such a span now, and the verbs that rewrite text treat it as before.

  • A zero-width-joiner sequence Unicode does not recommend counts as its parts. Segmentation joins any two pictographs a U+200D stands between, and nothing asked whether the result is a recommended sequence. Adult, girl and boy joined is not one: until 0.7.0 it was one emoji with no name, and now it is the three emoji nearly every platform draws, the longest catalogued parts read left to right. The verbs that rewrite text keep it whole, so "strip" removes the joiners with it and "name" names the parts in order. Microsoft's ninja-cat sequences (a cat joined to a laptop, a dragon, a rocket and three more) draw as one glyph on Windows and as a cat beside an object everywhere else, and here they count as the cat and the object, so a corpus written on Windows holds more emoji than its writers saw.

  • A request for the text form is honoured. U+FE0E after a glyph asks for its text presentation, a sequence Unicode's emoji-variation-sequences.txt defines for 371 bases. Under the default presentation = "emoji" such a glyph is not an emoji, exactly as a bare U+2764 is not, and the verbs that rewrite text leave it as text; under "any" it counts, with the selector inside the span, so "strip" removes all of it. Until 0.7.0 the 152 bases whose default is emoji (a watch, a star, the zodiac signs) and nine that take a skin tone (the index pointing up, the victory hand and seven more) were counted despite the request.

emoji_summary() counts the first two kinds in n_unlisted, so a count that moved between versions can be explained.

ASCII emoticons such as :) are not emoji and are never detected, so a study of the move from emoticons to emoji, which needs both in one denominator, has to count the emoticons itself.

Hidden payloads

A run of variation selectors after an emoji, or a string of Unicode tag characters, renders as nothing and can carry a message to whatever model reads the text next; emoji_hidden() reports and decodes them, and emoji_sanitize() and emoji_to_text() remove them by default. The rule is exact rather than a heuristic: a selector is hidden when it follows another, when an ideographic selector follows no CJK ideograph or when one of U+FE00 to U+FE0D forms no standardized variation sequence, and a tag character when it is outside a well-formed flag.

Glyphs, not people

emoji_decompose(), emoji_skin_tone(), emoji_gender() and emoji_retone() describe what a glyph depicts: the tone it is written in, the gender it is drawn with, its hair. They never infer the skin colour, gender or identity of anyone who wrote or read it. A tone is a keyboard setting on some platforms and an active choice on others, a gender is a design that every vendor draws differently, and a neutral form is Unicode's, not a person's. Writers mostly choose a tone close to their own (Robertson, Magdy and Goldwater 2018), which makes tones informative about writers only in aggregate, and readers infer identity even from the default yellow (CSCW 2021), which is exactly why a tool must not. Report counts of glyphs with their denominators, and leave people out of it.

Which spelling comes back

Two spellings of one emoji, differing only by U+FE0F, are one emoji to every lookup: the name, the score, the category and the type all resolve through a key that strips the selector. They are not always one row. A verb that reports a glyph either hands back the spelling it found or collapses both onto the catalogue's, and which it does follows from what the verb is for:

A corpus holding both spellings shows the difference in one line: emoji_frequency() returns two rows of n = 1 where emoji_cooccurrence() returns one node of n = 2. Nothing is lost either way, and the two sides line up on the name, which is the same for both spellings: emoji_frequency() already carries it, and as_emoji_name() supplies it for a glyph column of your own.

This is only ever about spellings of the same emoji. Skin tones, genders and the members of a ZWJ sequence are different emoji and stay apart in every verb.

Grouped data frames

Grouping is respected where it can be, and reported where it cannot. The verbs that work a row at a time – the ones that add .emoji_* columns, and the ones that keep or expand rows – carry the input's grouping through to their result, exactly as dplyr::mutate() and dplyr::filter() do, so a group_by() upstream still means something to a summarise() downstream. The verbs that pool across rows – emoji_frequency(), emoji_dfm(), emoji_pairs(), the time series, and the other corpus-level summaries – cannot honour groups yet: they warn and return a single corpus-wide answer. Splitting the data yourself, or passing a doc_id where the verb offers one, is the way to get per-group results today.

Author

Maintainer: Youzhi Yu yuyouzhi666@icloud.com

Authors:

Other contributors:

  • Unicode, Inc. (Unicode emoji and character data in R/sysdata.rda) [copyright holder]

  • OpenAssistant contributors (OASST2 example data in data/oasst_*.rda) [copyright holder]

  • emoji authors (snapshot of the emoji package's data in R/sysdata.rda) [copyright holder]

  • Miles Johnson (emojibase data in R/sysdata.rda and the crosswalk) [copyright holder]

  • Petra Kralj Novak (Emoji Sentiment Ranking in data/emoji_sentiment_lexicon.rda) [copyright holder]

  • Jasmina Smailovic (Emoji Sentiment Ranking) [copyright holder]

  • Borut Sluban (Emoji Sentiment Ranking) [copyright holder]

  • Igor Mozetic (Emoji Sentiment Ranking) [copyright holder]

  • Abu Awal Md Shoeb (EmoTag1200 in data/emoji_emotion_lexicon.rda) [copyright holder]

  • Gerard de Melo (EmoTag1200) [copyright holder]