1

Simple tutorial I am following using direct authentication, searchTwitter("") does return tweets.

     library(twitteR)
     library(plyr)
     library(tm)
     library(httr)
     library(wordcloud)
     library(RColorBrewer)
     reqURL <- "https://api.twitter.com/oauth/request_token"
     accessURL <- "https://api.twitter.com/oauth/access_token"
     authURL <- "https://api.twitter.com/oauth/authorize"
     apiKey <-  "my input"
     apiSecret <- "my input"

     setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret)

     tweets <- searchTwitter("#Trump", n=100)
     tweets.text = laply(tweets,function(t)t$getText())
     tweet.corpus = Corpus(VectorSource(tweets.text))

     tdm = TermDocumentMatrix(
     tweet.corpus,
     control = list(
     removePunctuation=FALSE,
     stopwords = c("Trump","trump","donald","Donald", stopwords("english")),
     removeNumbers= TRUE)
     )

     m = as.matrix(tdm)
     word_freqs = sort(rowSums(m), decreasing = TRUE)
     dm = data.frame(word=names(word_freqs), freq = word_freqs)

     wordcloud(dm$word, dm$freq, random.order = FALSE, colors = brewer.pal(8, "Dark2"))

This is the error i get and I have tried many variations of nearly every aspect of the code. Can anyone help me?

Error in simple_triplet_matrix(i = i, j = j, v = as.numeric(v), nrow = length(allTerms),  : 
  'i, j, v' different lengths
In addition: Warning messages:
1: In mclapply(unname(content(x)), termFreq, control) :
  all scheduled cores encountered errors in user code
2: In simple_triplet_matrix(i = i, j = j, v = as.numeric(v), nrow = length(allTerms),  :
  NAs introduced by coercion
epo3
  • 2,991
  • 2
  • 33
  • 60
user202815
  • 11
  • 5
  • `pacman::p_load(SnowballC)`; http://stackoverflow.com/questions/18504559/twitter-data-analysis-error-in-term-document-matrix – Hack-R Jul 07 '16 at 02:02
  • thnks for the reply. I tried implementing some of the changes and still no luck. – user202815 Jul 07 '16 at 13:51

0 Answers0