stansent icon indicating copy to clipboard operation
stansent copied to clipboard

Error with Text Highlighting in Stanford

Open 7evenHeadz opened this issue 5 years ago • 1 comments

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

7evenHeadz avatar Dec 30 '20 15:12 7evenHeadz

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)

saraemoore avatar Mar 17 '23 23:03 saraemoore