0

I am trying to write a code in r to do sentiment analysis by exporting and analyzing tweets,the following code is supposed to clean the tweet call up the sentiment package do the scoring and return back the result , this code has been cited in many tech blogs the code is as follows :

score.sentiment = function(sentences , pos.words, neg.words , progress='none')
{
 require(plyr)
 require(stringr)
 scores = laply(sentences,function(sentence,pos.words,neg.words)
 {
     sentence =gsub('[[:punct:]]','',sentence)
     sentence =gsub('[[:cntrl]]','',sentence)
     sentence =gsub('\\d+','',sentence)
     sentence=tolower(sentence)
     word.list=str_split(sentence,'\\s+')
     words=unlist(word.list)
     pos.matches=match(words,pos.words)
     neg.matches=match(words,neg.words)
     score=sum(pos.matches)-sum(neg.matches)
     return(score)
 },pos.words,neg.words,.progress=.progress)
 scores.df=data.frame(scores=scores,text=sentences)
 return(scores.df)
}  

However i keep on getting the following error:

Error in score.sentiment(Datasetgaza$text, pos.words, neg.words, .progress = "text") : unused argument (.progress = "text")

The argument passed was: gaza.scores=score.sentiment(Datasetgaza$text,pos.words,neg.words,.progress='text')

any help with the code would be very appreciated

Dominik Antal
  • 3,281
  • 4
  • 34
  • 50
  • 2
    Option of the function is `progress`, but in the code, it is `.progress`. I guess the former is a typo. Try by replacing `progress` with `.progress`. –  Jul 23 '14 at 06:12
  • Give us a link to one of these "many tech blogs" because they must have been using the same buggy code that you pasted. – Spacedman Jul 23 '14 at 07:21
  • According to [this page](http://jeffreybreen.wordpress.com/2011/07/04/twitter-text-mining-r-slides/), there is a typo in the code reproduced above. –  Jul 23 '14 at 10:06

1 Answers1

0

You missed a '.' in front of progress. sure this will help.

    score.sentiment = function(sentences , pos.words, neg.words , .progress='none')
{
 require(plyr)
 require(stringr)
 scores = laply(sentences,function(sentence,pos.words,neg.words)
 {
     sentence =gsub('[[:punct:]]','',sentence)
     sentence =gsub('[[:cntrl]]','',sentence)
     sentence =gsub('\\d+','',sentence)
     sentence=tolower(sentence)
     word.list=str_split(sentence,'\\s+')
     words=unlist(word.list)
     pos.matches=match(words,pos.words)
     neg.matches=match(words,neg.words)
     score=sum(pos.matches)-sum(neg.matches)
     return(score)
 },pos.words,neg.words,.progress=.progress)
 scores.df=data.frame(scores=scores,text=sentences)
 return(scores.df)
}