9

The "sentiment" package in R was removed from the Cran repository. What are the other packages which can do Sentiment Analysis?

For example, how I can rewrite this using other packages?

 library(sentiment)
# CLASSIFY EMOTIONS
classify_emotion(some_txt,algorithm="bayes",verbose=TRUE)
# classify polarity
class_pol = classify_polarity(some_txt, algorithm="bayes")

Where documents here is defined as:

# DEFINE text
some_txt<- c("I am very happy at stack overflow , excited, and optimistic.",
                "I am very scared from OP question, annoyed, and irritated.")
8
  • qdap does a polarity thing but it's low level at this point. Essentially it's a dictionary lookup system and may not scale well to large projects. It's intended more for discourse studies. Mar 4, 2013 at 4:14
  • 1
    you can do this , library(sos) ;findFn('sentiment analysis'), you have essentially, qdap and textir but there is also tm.plugin.sentiment for time series .. The sentiment package is still exist in R-Forge also.
    – agstudy
    Mar 4, 2013 at 4:38
  • 1
    The qdap::polarity function is an implementation based on the first link Ben provides but with a custom algorithm. I'm not happy with it but haven't had time to develop it further yet. Mar 4, 2013 at 4:42
  • 1
    @user1946217 I add some concrete example to your question..( I am joking for the text example, feel free to edit it)
    – agstudy
    Mar 4, 2013 at 5:43
  • 2
    @Dason yes I rewrote the algorithm to be more accurate and faster. It also takes into account negators (e.g., "It's not good" is ranked as a negative polarity rather than positive as "not" is accounted for). Other algorithms do not. Feb 19, 2015 at 23:37

4 Answers 4

12

I can't find sentiment package.This is based on the tm.plugin.sentiment package. You can find it here.

First, I create my Corpus:

some_txt<- c("I am very happy at stack overflow , excited, and optimistic.",
+              "I am very scared from OP question, annoyed, and irritated.")
 text.corpus <- Corpus(VectorSource(some_txt))

Then, I apply score on the corpus

> text.corpus <- score(text.corpus)

The result is stored in the meta :

> meta(text.corpus)
  MetaID polarity subjectivity pos_refs_per_ref neg_refs_per_ref senti_diffs_per_ref
1      0        0    0.2857143        0.1428571        0.1428571           0.0000000
2      0       -1    0.1428571        0.0000000        0.1428571          -0.1428571

behind the code The score function (the default behavior), will pre-procees the corpus using these tm functions:

  • tolower
  • removePunctuation
  • removeNumbers = TRUE,
  • removeWords = list(stopwords("english")),
  • stripWhitespace
  • stemDocument
  • minWordLength = 3,

Then, apply the score functions:

  • polarity
  • subjectivity
  • pos_refs_per_ref
  • neg_refs_per_ref
  • senti_diffs_per_ref
1
  • Each time the score() code throws an error: scored <- score(corpus.txt) Error in polarity.TermDocumentMatrix(list(i = c(2L, 6L, 8L, 11L, 12L, : could not find function "tm_tag_score". Others have encountered different errors: stackoverflow.com/questions/24612080/…. Can you advise or should I post a new question? Thank you.
    – lawyeR
    Apr 28, 2015 at 12:46
3

There is new R package called sentiment140, required no additional component installation nor language model training.

  • Easy to use
  • work with Twitter Text

Cool stuff !

http://github.com/okugami79/sentiment140

2

This is what I did to install 'sentiment' 0.2 in R version 3.0.2

I downloaded the 'sentiment_0.2.tar.gz' from the repository http://cran.r-project.org/src/contrib/Archive/sentiment/

Then I've put the 'sentiment_0.2.tar.gz' in the main directory --> C:

Then I used the command to install packages from local zip:

install.packages("C:/sentiment_0.2.tar.gz", repos = NULL, type="source")

This is what I've got:

Warning in install.packages :
  package ‘C:/sentiment_0.2.tar.gz’ is not available (for R version 3.0.2)

Installing package into ‘C:/Users/y65liu/Documents/R/win-library/3.0’
(as ‘lib’ is unspecified)

** installing source package 'sentiment' ...

** package 'sentiment' successfully unpacked and MD5 sums checked

** R

** data

** preparing package for lazy loading

** help

** installing help indices

** building package indices

** testing if installed package can be loaded

** DONE (sentiment) ?

When I call the library, the library is regularly loaded with its related packages ('tm', 'Rstem')

You may found documentation on using the sentiment package here:

https://sites.google.com/site/miningtwitter/questions/sentiment/sentiment
0

To install sentiment analysis package use this http://cran.r-project.org/web/packages/sentiment/index.html since the packages are quite old already and R cran removed them from their site.

the packages that are required before installing are tm , Rstem , twitteR,ggplot2,plyr,RColorBrewer and wordcloud it may provide some errors but I worked for me so far :P

2
  • That links to the package which the OP already told us is no longer in CRAN.
    – neilfws
    Apr 17, 2014 at 1:49
  • Yes but you can find it at the archives and then install the package manually in R
    – Napmi
    May 3, 2014 at 12:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.