emoji_to_text() returns a copy of data with its text column rewritten so
that every emoji is replaced by its name or shortcode. This is useful for
accessibility (screen readers) and as an NLP normalisation step before
tokenising. Detection is grapheme-aware and joins go through emoji_key(),
so emoji carrying the U+FE0F variation selector still resolve.
Usage
emoji_to_text(data, text, format = c("name", "shortcode"), wrap = ":{x}:")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.- format
Output form:
"name"(the Unicode name, e.g. "grinning face") or"shortcode"(the canonical GitHub-style alias, e.g. "grinning", wrapped as ":grinning:"). Default"name".- wrap
When
format = "shortcode", the wrapper applied to each shortcode, written as a template with{x}standing for the shortcode. Default":{x}:". Must contain{x}, or every emoji would be replaced by the same literal string. Ignored forformat = "name".Only the default is reversible by
text_to_emoji(), which looks for exactly:shortcode:; awrapthat does not produce that token leaves the shortcode in the text as an ordinary word, silently. Seeemoji_sanitize()for the cases.
Value
data, as a tibble, with the text column rewritten in place (same
column name). NA entries stay NA, and emoji with no known name are left
in place unchanged.
See also
text_to_emoji() for the inverse (emojize); as_emoji_name(),
as_emoji_shortcode(), as_emoji() for vector helpers.
Examples
df <- data.frame(text = "great \U0001f600 love \u2764\ufe0f")
emoji_to_text(df, text, format = "name")
#> # A tibble: 1 × 1
#> text
#> <chr>
#> 1 great grinning face love red heart
emoji_to_text(df, text, format = "shortcode")
#> # A tibble: 1 × 1
#> text
#> <chr>
#> 1 great :grinning: love :heart: