Getting Text From Tweets


I am tring to read my tweets from a csv file (which I have downloaded previously), and I am having some problems:

sia.list <- searchTwitter('#singaporeair', n=10, since=NULL, until=NULL, cainfo="cacert.pem") sia.df = twListToDF(sia.list) write.csv(sia.df, file='C:/temp/siaTweets.csv', row.names=F)

I am trying to extract the text from the list and the problems is with the third line below:

sia.df <- read.csv(file=paste(path,"siaTweets.csv",sep="")) sia.list <- as.list(t(sia.df)) sia_txt = sapply(sia.list, function(x) x$getText())

console output:

> sia.list <- as.list(t(sia.df)) > sia_txt = sapply(sia.list, function(x) x$getText()) Error in x$getText : $ operator is invalid for atomic vectors


If you want to read the text from a csv file , all you have to do is : sia_txt <- sia$text (text being the name of the column in which your text is stored.)

the x$getText you've used in saaply is a method available only to lists which come as result of searchTwitter(). Hence you cannot convert a DF back to List and use getText. For e.g. do:

xyz <- searchTwitter("#xyz", n = 100)


You will see a list of methods applicable. something like:

$ :Reference class 'status' [package "twitteR"] with 17 fields ..$ text : chr "RT @BET: \"Who's left to love the black woman?\" ~ WATCH last night's #BeingMaryJane here:\nhttp://t.co/xiUho1FVQi http://t.co/"| __truncated__ ..$ favorited : logi FALSE ..$ favoriteCount: num 0 ..$ replyToSN : chr(0) ..$ created : POSIXct[1:1], format: "2015-03-11 13:28:01" ..$ truncated : logi FALSE ..$ replyToSID : chr(0) ..$ id : chr "575649378062434304" ..$ replyToUID : chr(0) ..$ statusSource : chr "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>" ..$ screenName : chr "kookie_kay" ..$ retweetCount : num 20 ..$ isRetweet : logi TRUE

and 51 methods, of which 39 are possibly relevant: .. getCreated, getFavoriteCount, getFavorited, getId, getIsRetweet, getLatitude, getLongitude, getReplyToSID, .. getReplyToSN, getReplyToUID, getRetweetCount, getRetweeted, getRetweeters, getRetweets, getScreenName, .. getStatusSource, **getText**, getTruncated, getUrls, initialize

Notice the getText.


<em>x$getText()</em> doesn't really make sense here. Because you are using <em>sapply()</em>, each element of <em>sia.list</em> is what gets passed to x, and these don't have sub-elements you can access using the $ operator.

What is <em>getText()</em>? It's not a function in base r or in the twitteR package. If it's a function from some other package, maybe <em>getText(x)</em> is what you want, but it's hard to say without knowing more about where it comes from.


  • Using ifelse with random variate generation in a function applied to a vector
  • Convert from DataFrame to JavaPairRDD
  • Program crashes when run outside IDE
  • Most efficient way to replace lowest list values in dataframe in R
  • Retrieving specified columns from a list of csv files to create a data data frame in R
  • How to override value that appears in a dropdown in the rails_admin gem
  • Convert SQLite database to XML
  • WPF Visiblity Binding to Boolean Expression with multiple Variables
  • Conversion from string “a” to type 'Boolean' is not valid
  • Groovy: Unexpected token “:”
  • Keep this build forever option - Jenkins
  • Converting a WriteableBitmap image ToArray in UWP
  • Replace value with Factor in r data.table
  • How to access EntityManager inside Entity class in EJB3
  • Repeat a vertical line on every page in Report Builder / SSRS
  • Is there any way to access browser form field suggestions from JavaScript?
  • Deserializing XML into class C#
  • Trying to switch camera back to front but getting exception
  • Hazelcast - OperationTimeoutException
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • php design question - will a Helper help here?
  • Arrays break string types in Julia
  • Comma separated Values
  • SQL merge duplicate rows and join values that are different
  • AngularJs get employee from factory
  • Free memory of cv::Mat loaded using FileStorage API
  • Angular 2 constructor injection vs direct access
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Authorize attributes not working in MVC 4
  • Bitwise OR returns boolean when one of operands is nil
  • python draw pie shapes with colour filled
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Programmatically clearing map cache
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?