Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

replace_emoji

Replace Emojis With Words/Identifier


Description

Replaces emojis with word equivalents or a token identifier for use in the sentimentr package. Not that this function will coerce the text to ASCII using Encoding(x) <- "latin1"; iconv(x, "latin1", "ASCII", "byte"). The function replace_emoji replaces emojis with text representations while replace_emoji_identifier replaces with a unique identifier that corresponds to lexicon::hash_sentiment_emoji for use in the sentimentr package.

Usage

replace_emoji(x, emoji_dt = lexicon::hash_emojis, ...)

replace_emoji_identifier(x, emoji_dt = lexicon::hash_emojis_identifier, ...)

Arguments

x

The text variable.

emoji_dt

A data.table of emojis (ASCII byte representations) and corresponding word/identifier meanings.

...

Other arguments passed to .mgsub (see textclean:::.mgsub for details).

Value

Returns a vector of strings with emojis replaced with word equivalents.

Examples

fls <- system.file("docs/emoji_sample.txt", package = "textclean")
x <- readLines(fls)[1]
replace_emoji(x)
replace_emoji_identifier(x)

textclean

Text Cleaning Tools

v0.9.3
GPL-2
Authors
Tyler Rinker [aut, cre], ctwheels StackOverflow [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.