trinker / sentimentr

Dictionary based sentiment analysis that considers valence shifters
Other
427 stars 84 forks source link

highlight() not using the supplied averaging function from sentiment_by() #103

Closed trinker closed 5 years ago

trinker commented 5 years ago

Reported by Kelvin Lam Lamkel@outlook.com

FIrst of all, thank you for the great sentimentr package. I am using it currently for a POC and it's going great so far.

I have a question about highlight(). I am using average_downweighted_zero for sentiment_by, and the output data frame looks good. However, the highlight() seems to be using the mean instead, and I found the avg sentiments aren't matching those in the highlighted html whenever there's zero sentiment score.

MWE

library(magrittr)
library(dplyr)

hu_liu_cannon_reviews %>%
    filter(review_id %in% sample(unique(review_id), 3)) %>%
    mutate(review = get_sentences(text)) %$%
    sentiment_by(review, review_id) 

hu_liu_cannon_reviews %>%
    filter(review_id %in% sample(unique(review_id), 3)) %>%
    mutate(review = get_sentences(text)) %$%
    sentiment_by(review, review_id) %>%
    highlight()