emoji_score() is the generic scorer that the friendly verbs
(emoji_sentiment(), emoji_emotion()) sit on top of. It joins each row's
emoji to lexicon through emoji_key() and returns the per-row mean of the
score column, plus the number of emoji scored. Bring your own lexicon, or
name a bundled / registered one.
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.- lexicon
Either a string naming a bundled or registered lexicon, or a data frame. For data frames,
bynames the glyph column andscorethe score column. Defaults to"novak2015", matchingemoji_sentiment().Two requirements on a data frame, both refused rather than worked around. The score column must be numeric or logical: as text every score comes back
NAwhile the emoji still counts as scored, which contradicts.emoji_n_scoredbelow. And no two rows may give one emoji different scores – spellings differing only by a variation selector share a single code-point key, so a table listing bothU+2764andU+2764 U+FE0Fhas one emoji twice. Identical scores are fine and collapse silently; when they differ, the row order would be choosing the answer.A third value is neither refused nor used: an infinite score warns and is treated as missing, so the emoji carrying it counts as unscored. It is the same rule
emoji_incongruity()applies to a non-finitetext_score, and the same oneNAandNaNalready got. Left alone, oneInfmakes every row that meets it infinite while.emoji_n_scoredstill reports the row as scored. This applies to an emotion lexicon's dimensions too, and those must be numeric for the reason the score column must be.- by
Glyph column name when
lexiconis a data frame, as a single string. Default"emoji". Ignored whenlexiconnames a bundled or registered lexicon, which carries its own key.- score
Score column name when
lexiconis a data frame. IfNULL,"sentiment_score"then"score"are tried. Ignored, likeby, whenlexiconis a name rather than a table.
Value
data, as a tibble, with .emoji_n (total emoji),
.emoji_n_scored (emoji found in the lexicon) and .emoji_score
(per-row mean) added, in that order – the same order
emoji_sentiment(), emoji_emotion(), emoji_risk(),
emoji_incongruity() and emoji_faceness() use.
For the multi-dimensional "emotag1200" lexicon the score is the mean
over its eight emotion dimensions; use emoji_emotion() for the
per-emotion profile. Note the scale changes with the lexicon.
"novak2015" is a signed valence on [-1, 1], where the sign is the
direction of sentiment. The "emotag1200" mean is an intensity on
[0, 1]: its eight dimensions are each non-negative and four of them
(anger, disgust, fear, sadness) are negatively valenced, so a maximally
angry emoji and a maximally joyful one score alike and neither is
negative. The two are not comparable and must not be pooled.
That averaging is specific to the bundled lexicon. A registered or
inline lexicon carrying emotion columns has no score column, so
emoji_score() cannot collapse it and says so: pass it to
emoji_emotion() instead, or name one dimension with
score = "joy" to score on that alone.
.emoji_n_scored distinguishes the two ways a score can be missing, as in
emoji_sentiment(): 0 means the row had emoji that the lexicon could not
score, NA that it had no emoji to score. .emoji_n counts every emoji
either way.
Examples
df <- data.frame(text = c("love \U0001f60d", "angry \U0001f621", "meh"))
emoji_score(df, text, lexicon = "novak2015")
#> # A tibble: 3 × 4
#> text .emoji_n .emoji_n_scored .emoji_score
#> <chr> <int> <int> <dbl>
#> 1 love 😍 1 1 0.678
#> 2 angry 😡 1 1 -0.173
#> 3 meh 0 NA NA
# a bring-your-own lexicon
own <- data.frame(emoji = c("\U0001f600", "\U0001f621"),
score = c(0.9, -0.8))
emoji_score(df, text, lexicon = own)
#> # A tibble: 3 × 4
#> text .emoji_n .emoji_n_scored .emoji_score
#> <chr> <int> <int> <dbl>
#> 1 love 😍 1 0 NA
#> 2 angry 😡 1 1 -0.8
#> 3 meh 0 NA NA