R: Extract Sentiment Words

extract_sentiment_terms {sentimentr} | R Documentation

## Extract Sentiment Words

### Description

Extract the sentiment words from a text.

### Usage

    extract_sentiment_terms(text.var,
      polarity_dt = lexicon::hash_sentiment_jockers_rinker, hyphen = "",
      ...)

### Arguments

`text.var` | The text variable.
`polarity_dt` | A data.table of positive/negative words and weights with x and y as column names.
`hyphen` | The character string to replace hyphens with. Default replaces with nothing so 'sugar-free' becomes 'sugarfree'. Setting `hyphen = " "` would result in a space between words (e.g., 'sugar free').
`...` | Ignored.

### Value

Returns a data.table with columns of positive and negative terms.

### Examples

    library(data.table)
    set.seed(10)
    x <- get_sentences(sample(cannon_reviews[[2]], 1000, TRUE))
    sentiment(x)

    pol_words <- extract_sentiment_terms(x)
    pol_words
    pol_words$sentence
    pol_words$neutral
    data.table::as.data.table(pol_words)

    attributes(extract_sentiment_terms(x))$counts
    attributes(extract_sentiment_terms(x))$elements

[Package sentimentr version 2.4.2 Index]