trinker / stansent

16 stars 3 forks source link

Error with Text Highlighting in Stanford #11

Open 7evenHeadz opened 3 years ago

7evenHeadz commented 3 years ago

The error which comes with the highlight function is

Error in [.data.table(y, , list(sentiment = attributes(x)["averaging.function"], : attempt to apply non-function

The highlight function was working fine with both stansent and sentimentr previously but now only works with sentimentr. The sentimentr package used is V 2.8.1

saraemoore commented 1 year ago

This issue seems to be due to an update in sentimentr to fix a reported issue. Manually adding the attribute worked for me:

library(sentimentr)
library(stansent)

data(presidential_debates_2012)
set.seed(100)
dat <- presidential_debates_2012[sample(1:nrow(presidential_debates_2012), 100), ]
out <- with(dat, sentiment_stanford_by(dialogue, list(person, time), stanford.tagger = "/path/to/stanford-corenlp/"))

attributes(out)[["averaging.function"]] <- stansent::average_downweighted_zero
highlight(out)