0

i am very new to sentiment analysis. I am running the codes based on the tutorial here

It is using a tidytext package. But I encountered the problem when I run the code

AFINN <- sentiments %>%
  filter(lexicon == "AFINN") %>%
  select(word, afinn_score = score)

AFINN

The error is as below

Error: Problem with `filter()` input `..1`.
✖ object 'lexicon' not found
ℹ Input `..1` is `lexicon == "AFINN"`.

I guess it is because the lexicon column is not in the sentiments dataframe. Or is the tidytext package changed so that i could not run the code the way that the tutorial ran it? is there any other way to correct the code or run another similar code?

Thank you in advance for your clarification.

Progman
  • 16,827
  • 6
  • 33
  • 48

1 Answers1

0

I followed the same tutorial and had to make the following change

AFINN <- sentiments %>%
  filter(lexicon == "AFINN") %>%
  select(word, afinn_score = score)

becomes

AFINN <- get_sentiments("afinn") %>%
  select(word, afinn_score = value)

Then the rest of the tutorial worked

  • Can you explain why it has to be changed like that? – Alex Berger Feb 16 '21 at 16:56
  • sentiments only has the 'bing' lexicon by default and no column for lexicon type anymore. This seems to be due to a licensing issue https://juliasilge.com/blog/sentiment-lexicons/ and the other lexicons need to be downloaded upon request. – Goldsmif Feb 18 '21 at 10:00