我正在将 twitter 搜索结果保存到数据库(SQL Server)中,当我从 twitteR 中提取搜索结果时出现错误。
如果我执行:
library(twitteR)
puppy <- as.data.frame(searchTwitter("puppy", session=getCurlHandle(),num=100))
我收到以下错误:
Error in as.data.frame.default(x[[i]], optional = TRUE) :
cannot coerce class structure("status", package = "twitteR") into a data.frame
这很重要,因为为了使用 RODBC 将其添加到使用 sqlSave 的表中,它需要是一个 data.frame。至少这是我得到的错误信息:
Error in sqlSave(localSQLServer, puppy, tablename = "puppy_staging", :
should be a data frame
那么有人对如何将列表强制为 data.frame 或如何通过 RODBC 加载列表有任何建议吗?
我的最终目标是创建一个能反映 searchTwitter 返回值结构的表。这是我尝试检索和加载的示例:
library(twitteR)
puppy <- searchTwitter("puppy", session=getCurlHandle(),num=2)
str(puppy)
List of 2
$ :Formal class 'status' [package "twitteR"] with 10 slots
.. ..@ text : chr "beautifull and kc reg Beagle Mix for rehomes: This little puppy is looking for a new loving family wh... http://bit.ly/9stN7V "| __truncated__
.. ..@ favorited : logi FALSE
.. ..@ replyToSN : chr(0)
.. ..@ created : chr "Wed, 16 Jun 2010 19:04:03 +0000"
.. ..@ truncated : logi FALSE
.. ..@ replyToSID : num(0)
.. ..@ id : num 1.63e+10
.. ..@ replyToUID : num(0)
.. ..@ statusSource: chr "<a href="http://twitterfeed.com" rel="nofollow">twitterfeed</a>"
.. ..@ screenName : chr "puppy_ads"
$ :Formal class 'status' [package "twitteR"] with 10 slots
.. ..@ text : chr "the cutest puppy followed me on my walk, my grandma won't let me keep it. taking it to the pound sadface"
.. ..@ favorited : logi FALSE
.. ..@ replyToSN : chr(0)
.. ..@ created : chr "Wed, 16 Jun 2010 19:04:01 +0000"
.. ..@ truncated : logi FALSE
.. ..@ replyToSID : num(0)
.. ..@ id : num 1.63e+10
.. ..@ replyToUID : num(0)
.. ..@ statusSource: chr "<a href="http://blackberry.com/twitter" rel="nofollow">Twitter for BlackBerry®</a>"
.. ..@ screenName : chr "iamsweaters"
所以我认为小狗的 data.frame 应该有如下列名:
- text
- favorited
- replytoSN
- created
- truncated
- replytoSID
- id
- replytoUID
- statusSource
- screenName