代码之家  ›  专栏  ›  技术社区  ›  analyticsPierce

关于plyr错误的问题:as.double(y)中的错误:无法将类型“s4”强制为类型“double”的向量

  •  1
  • analyticsPierce  · 技术社区  · 15 年前

    我正在升级以前工作过的项目。这个代码几个月前就开始工作了,同时我已经升级了R和PLYR。我想我是在R1.10上,现在我是在R1.35上,我不确定我以前运行的PLYR是什么版本,但我当前安装的版本是1.2。

    以下是我要运行的内容:

    library(plyr)
    library(twitteR)
    
    tw <- head(ldply(searchTwitter("rstats", session=getCurlHandle(), n=10), function(x) data.frame(text=text(x), favorited=favorited(x), created=created(x), truncated=truncated(x), id=id(x), statusSource=statusSource(x), screenName=screenName(x))))
    

    我现在总是收到相同的错误消息。

    Error in as.double(y) : 
      cannot coerce type 'S4' to vector of type 'double'
    

    任何建议都将不胜感激。

    谢谢,

    杰森

    2 回复  |  直到 15 年前
        1
  •  4
  •   Gavin Simpson    15 年前

    sessionInfo()

    text() statusText()

    CRAN :::

    twitteR:::statusSource(x)
    

    library(plyr)
    library(twitteR)
    ## simplify the call to see what is going on - function first
    fooFun <- function(x) {
        data.frame(text = statusText(x), favorited=favorited(x),
                   created=created(x), truncated=twitteR:::truncated(x),
                   id=id(x), statusSource=twitteR:::statusSource(x),
                   screenName=screenName(x))
    }
    ## now ldply it
    out <- ldply(searchTwitter("rstats", session = getCurlHandle(), n = 10), fooFun)
    ## show some of it:
    head(out)
    
        2
  •  1
  •   IRTFM    15 年前

    tw <- ldply(searchTwitter("rstats", session=getCurlHandle(), n=10), 
                  function(x)  c(text=x@text, favorited=x@favorited, created=x@created, 
                                 truncated=x@truncated, id=x@id, statusSource=x@statusSource, 
                                 screenName=x@screenName )
                              )