user2543622
user2543622

Reputation: 6756

r twitteR package

I was reading documentation of TwitteR package. For searchTwitter it says that R returns A list of status objects. status-class documentation lists several fields and methods.

But as shown below, class(x) returns list, why? shouldn't it return a status object? Also last two commands dont work, why?

The documentation says that

toDataFrame: Converts this into a one row data.frame, with each field 
representing a column.
This can also be accomplished by the S4 style as.data.frame(objectName)


x=searchTwitter("Samsung")
> class(x)
[1] "list"
> abc=as.data.frame(x)
Error in as.data.frame.default(x[[i]], optional = TRUE) : 
  cannot coerce class "structure("status", package = "twitteR")" to a data.frame
> x$text
NULL

Upvotes: 0

Views: 98

Answers (1)

neilfws
neilfws

Reputation: 33772

If x is a list of status objects, then the class of x is list. The class of each element in the list is status-class.

You might try something like:

class(x[[1]])

to check that this is correct.

Similarly, toDataFrame acts on objects of class status-class - again, the elements of the list, not the list itself. You might try:

toDataFrame(x[[1]])

and

x[[1]]$text

If your aim is to get every element of the list into a single data frame, the function you should be looking at is twListToDF.

Upvotes: 3

Related Questions