0

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
M--
  • 25,431
  • 8
  • 61
  • 93
sam
  • 85
  • 3
  • 10
  • Some of these datasets are no longer included in tidytext itself because of license issues anymore. You will need to run the function one time interactively to download the dataset (and agree to the license). After that, you will be able to use the dataset when, for example, knitting a document. – Julia Silge Jul 30 '19 at 13:54

4 Answers4

1

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.

markhogue
  • 1,056
  • 1
  • 6
  • 16
0

YEs I would say update then try !

  • updated 3.6.1 Now this error:Selection: 1 trying URL 'https://www2.imm.dtu.dk/pubdb/views/edoc_download.php/6010/zip/imm6010.zip' Content type 'text/html' length 86 bytes ================================================== downloaded 86 bytes Error in open.connection(con, "rb") : cannot open the connection In addition: Warning message: In open.connection(con, "rb") : cannot open zip file '/root/.cache/textdata/afinn/imm6010.zip' Any leads ? – sam Aug 02 '19 at 17:49
0

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

0

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"

GRC
  • 1
  • 2