5

只是想知道,有没有改变 R 列表对象的字符编码?我有一种感觉,我将不得不采取多个步骤,但我不确定。我已经用谷歌搜索了这个主题,但我并没有从互联网上获得帮助。

例如,考虑以下内容:

 library(twitteR)
 library(RJSONIO)


 #Authorize with Twitter's API
 reqURL <- "https://api.twitter.com/oauth/request_token"
 accessURL <- "http://api.twitter.com/oauth/access_token"
 authURL <- "http://api.twitter.com/oauth/authorize"
 consumerKey = "myconsumerkey"
 consumerSecret = "myconsumersecret"
 twitCred <- OAuthFactory$new(consumerKey=consumerKey,
                         consumerSecret=consumerSecret,
                         requestURL=reqURL,
                         accessURL=accessURL,
                         authURL=authURL)
  twitCred$handshake()

  B<-read.csv("BCorp RAW.csv") 
  handles<-B$Twitter.handle
  handles<-na.omit(handles)

  start <- getUser(handles[12])                        

  library(rjson)
  friends.object<- lookupUsers(start$getFriendIDs(), includeNA=TRUE)
  followers.object<-lookupUsers(start$getFollowerIDs(), includeNA=TRUE)

命令

   followers.object<-lookupUsers(start$getFollowerIDs(), includeNA=TRUE)

引发以下错误:

   Error in twFromJSON(out) : 
   Error: Malformed response from server, was not JSON.
    The most likely cause of this error is Twitter returning a character which
    can't be properly parsed by R. Generally the only remedy is to wait long
    enough for the offending character to disappear from searches (e.g. if
    using searchTwitter()).

使用 twitter 时如何允许 R 保留特殊字符?希望我编辑得很好......如果你想让我再次编辑它,请告诉我

谢谢你,

4

1 回答 1

0

有一个Encoding<-函数可以让您指定字符向量的编码。列表元素在同一个列表中可能具有不同的编码,但字符向量中的所有元素都将具有相同的编码。此外,还有 'fileEncoding' 和 'encoding' 参数read.table及其read.*表亲允许您以默认值以外的方式读取字符数据。

?Encoding
?read.table

Rhelp 档案中也回答了很多编码问题。

于 2013-10-21T21:02:09.527 回答