简体   繁体   中英

sentiments dataset in R throwing error with AFINN lexicon

Trying to access the sentiments data set for the "AFINN" lexicon using the function get_sentiments("afinn")

R code :

library(textdata)
get_sentiments("afinn")

Throwing below error message

Do you want to download: Name: AFINN-111 Error in menu(choices = c("Yes", "No"),title = title): menu() cannot be used non-interactively

I tried running it in R3.6.1 with Windows 10 and a fresh install of tidytext. I get the option to download...

> library(tidytext)
> get_sentiments("afinn")
Do you want to download:
 Name: AFINN-111 
 URL: http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6010 
 License: Open Database License (ODbL) v1.0 
 Size: 78 KB 
 Download mechanism: https 

1: Yes
2: No

Selection: 

Maybe you're not getting this due to not having the latest R version or something else with your operating system. My only suggestion is get the latest R and latest package.

是的,我会说更新然后尝试!

I have the similar issue when i run it on Jupyter but Colab is working fine. You may run it on RGui where interactive() should return TRUE which enable you to type "Yes" into the "Selection" so that the download can be completed.

Is R running interactively

I bypassed these downloading issues by doing a manual download.

First (Download) : try manually downloading the AFINN-111 document, currently at http://www2.imm.dtu.dk/pubdb/pubs/6010-full.html or simply do a web search. This will Download the imm6010.zip file, which is what the textdata library package is specifically seeking to access the AFINN-111 text document.

Second (Identify AFINN directory) : go to the R terminal, enter

library(textdata)

textdata::lexicon_afinn(manual_download = TRUE)  

The code will push a warning "cannot open zip file 'C:/path/to/afinn/directory...imm6010.zip'

Third (Move file to AFINN directory) : move the imm6010.zip file from your download directory to the textdata afinn directory (given by the previous warning). One way of accomplishing the task, open bash (Unix shell) and enter the following:

mv /your/path/from/download_directory/ /your/path/to/textdata/afinn_directory/

Then retry the R code:

textdata::lexicon_afinn(manual_download = TRUE)

If imm6010.zip is copied to the correct path, textdata will then have access to the AFINN-111.txt document and the function you were having trouble with, get_sentiments("afinn") will work.

Fourth (check headers) . That is the newer afinn text document has replaced the "score" header with the term "value" so be sure to update your R code, if the following warning is given: "The following named parsers don't match the column names: score"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM