extract_emotion_terms {sentimentr} | R Documentation |
Extract Emotion Words
Description
Extract the emotion words from a text.
Usage
extract_emotion_terms(
text.var,
emotion_dt = lexicon::hash_nrc_emotions,
un.as.negation = TRUE,
retention_regex = "[^[:alpha:];:,']",
...
)
Arguments
text.var |
The text variable. Can be a |
emotion_dt |
A data.table with a |
un.as.negation |
logical. If |
retention_regex |
A regex of what characters to keep. All other
characters will be removed. Note that when this is used all text is lower
case format. Only adjust this parameter if you really understand how it is
used. Note that swapping the |
... |
Ignored. |
Value
Returns a data.table with a columns of emotion terms.
Examples
## Not run:
mytext <- c(
"I am not afraid of you",
NA,
"",
"I love it [not really]",
"I'm not angry with you",
"I hate it when you lie to me. It's so humiliating",
"I'm not happpy anymore. It's time to end it",
"She's a darn good friend to me",
"I went to the terrible store",
"There is hate and love in each of us",
"I'm no longer angry! I'm really experiencing peace but not true joy.",
paste("Out of the night that covers me, Black as the Pit from pole to",
"pole, I thank whatever gods may be For my unconquerable soul.",
"In the fell clutch of circumstance I have not winced nor cried",
"aloud. Under the bludgeonings of chance My head is bloody, but unbowed.",
"Beyond this place of wrath and tears Looms but the Horror of the",
"shade, And yet the menace of the years Finds, and shall find, me unafraid.",
"It matters not how strait the gate, How charged with punishments",
"the scroll, I am the master of my fate: I am the captain of my soul."
)
)
mytext2 <- get_sentences(mytext)
emotion(mytext2)
emo_words <- extract_emotion_terms(mytext2)
emo_words
emo_words$sentence
emo_words[, c('anger', 'anticipation', 'disgust', 'fear', 'joy', 'sadness', 'surprise', 'trust')]
attributes(emo_words)$counts
attributes(emo_words)$elements
## directly ona character string (not recommended: use `get_sentences` first)
extract_emotion_terms(mytext)
brady <- get_sentences(crowdflower_deflategate)
brady_emo <- extract_emotion_terms(brady)
brady_emo
attributes(brady_emo)$counts
attributes(brady_emo)$elements
## End(Not run)