0

I am an ML enthusiast.Recently I have started using R and its packages.But I am not able to install sentiment package for R 3.2.0.I have googled about this problem. It says that sentiment package is no longer available for R 3.2.0.But I have seen in many github repositories where sentiment package is not used but still its files are being used.My main problem is how do I use sentiment package for R 3.2.0?

knbdtu
  • 65
  • 3
  • 11
  • @figurine: The code of the possible duplicate does not work. I left a comment for agstudy there describing the errors after score() [as well as an earlier SO question, unanswered, on a related error]. – lawyeR Apr 28 '15 at 12:48
  • Looks like I can't add an answer but I can comment. I was able to install the tm.plugin.sentiment from github directly (for R 3.2.0): install.packages("devtools") library(devtools) install_github("mannau/tm.plugin.sentiment") – Daghan --- Oct 27 '15 at 13:20

1 Answers1

4

Here is a starting point. First is some code to install the sentiment plug ins (thank you, Dason, for the useful comment).

Next, with some text from a previous SO post to show what you might do, you can create a data frame.

Install the packages for sentiment analysis:

# install.packages("tm.lexicon.GeneralInquirer", repos="http://datacube.wu.ac.at", type="source")
library(tm.lexicon.GeneralInquirer)
# install.packages("tm.plugin.sentiment", repos="http://R-Forge.R-project.org")
library(tm.plugin.sentiment) # posted comments on SO about this not working
library(tm)

Using the installed functions:

some_txt<- c("I am very happy at stack overflow , excited, and optimistic.",
             "I am very scared from OP question, annoyed, and irritated.", "I am completely neutral about blandness.")
corpus <- Corpus(VectorSource(some_txt)) 
pos <- sum(sapply(corpus, tm_term_score, terms_in_General_Inquirer_categories("Positiv")))
neg <- sum(sapply(corpus, tm_term_score, terms_in_General_Inquirer_categories("Negativ")))
pos.score <- tm_term_score(TermDocumentMatrix(corpus, control = list(removePunctuation = TRUE)), 
                           terms_in_General_Inquirer_categories("Positiv")) # this lists each document with number below

neg.score <- tm_term_score(TermDocumentMatrix(corpus, control = list(removePunctuation = TRUE)), 
                           terms_in_General_Inquirer_categories("Negativ")) 

total.df <- data.frame(positive = pos.score, negative = neg.score)
total.df <- transform(total.df, net = positive - negative)

  positive negative net
1        3        1   2
2        0        1  -1
3        0        0   0
lawyeR
  • 7,488
  • 5
  • 33
  • 63
  • How is this an answer to the question? – Dason Apr 28 '15 at 13:04
  • I tells how to install the sentiment functions and uses them in a test case. That is what OP asked about. – lawyeR Apr 28 '15 at 13:11
  • Ok. Their main question is getting it installed though. I would suggest actually separating that out and explaining how to install it since that is the actual question. – Dason Apr 28 '15 at 14:01
  • Not to be argumentative, but the final sentence asks about how to use the package. I tried to address both points of installation and use. Possibly reconsider the down vote? :) – lawyeR Apr 28 '15 at 14:22
  • I didn't downvote. My take on the last sentence was just reiterating that they couldn't install it. You can't use it if you don't have access to it. I can see where you're coming from with that last line. I still think separating out the install code and adding a little explanation would be a good idea and would net you an upvote from me. – Dason Apr 28 '15 at 14:26