stansent
stansent copied to clipboard
Error with Text Highlighting in Stanford
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
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)