register_emoji_lexicon() adds a user-supplied lexicon to the in-session
registry so it can be referenced by name in emoji_score(),
emoji_sentiment() or emoji_emotion(). The lexicon is normalised through
the package's codepoint key (U+FE0F stripped), so a lexicon keyed on
unqualified glyphs still matches qualified text.
Arguments
- name
Name to register the lexicon under.
- tbl
A data frame. Must contain a glyph column named
by(default"emoji") and at least one score column, and every score column present must be numeric or logical – a text column is rejected here rather than returningNAfor every score at first use. Seeemoji_score()for the one-row-per-emoji requirement, which is checked when the lexicon is used.- by
Name of the column holding the emoji glyph, as a single string. Default
"emoji".
Value
Invisibly, the registered lexicon, with a key column holding the
code-point key of each glyph. A key column already in tbl is
replaced rather than trusted: the registry looks a lexicon up by that
column, so one holding anything else would resolve every row to nothing.
Details
Registration lasts for the session; it is not written to disk. Registering
a name that is already taken replaces the table under it, without warning
and without a way to get the old one back: there is no public counterpart
that removes a registration, so re-registering is how a lexicon is
changed. emoji_lexicons() shows what is currently registered.
See also
emoji_lexicons() to list lexicons; emoji_score() to use one.
Examples
my_lex <- data.frame(
emoji = c("\U0001f600", "\U0001f621"),
score = c(0.9, -0.8)
)
register_emoji_lexicon("mine", my_lex)
emoji_lexicons()
#> # A tibble: 3 × 6
#> name type dimensions n source licence
#> <chr> <chr> <I<list>> <int> <chr> <chr>
#> 1 novak2015 sentiment <chr [1]> 969 Kralj Novak et al. (2015), PLoS… CC BY-…
#> 2 emotag1200 emotion <chr [8]> 150 Shoeb & de Melo (2020), EMNLP 2… MIT
#> 3 mine custom <chr [1]> 2 user-registered NA
emoji_score(data.frame(text = "great \U0001f600"), text, lexicon = "mine")
#> # A tibble: 1 × 4
#> text .emoji_n .emoji_n_scored .emoji_score
#> <chr> <int> <int> <dbl>
#> 1 great 😀 1 1 0.9