简体   繁体   中英

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM