如何使getURL函数在R中工作?

时间:2018-11-10 17:28:06

标签: r function

我正在R Studio中尝试使用JSON,并且已经成功安装了RJSONIO和Rcurl软件包,但是getURL函数无法正常工作。我不断收到一条错误消息,指出找不到getURL函数。

  package ‘RCurl’ successfully unpacked and MD5 sums checked
  Warning in install.packages :
  cannot remove prior installation of package ‘RCurl’

 > AccidentURL <- "http://data.maryland.gov/api/views/pdvh-tf2u/rows.json? 
 accessType=DOWNLOAD"
 > apiResult <- getURL(AccidentURL)
 Error in getURL(AccidentURL) : could not find function "getURL"

任何有关如何使该功能正常工作或如何自行构建该功能的建议将不胜感激。

1 个答案:

答案 0 :(得分:0)

library(httr)
AccidentURL <- "http://data.maryland.gov/api/views/pdvh-tf2u/rows.json?accessType=DOWNLOAD"
apiResult <- GET(AccidentURL)

输出

apiResult
    Response [http://data.maryland.gov/api/views/pdvh-tf2u/rows.json?accessType=DOWNLOAD]
      Date: 2018-11-10 17:33
      Status: 200
      Content-Type: application/json; charset=utf-8
      Size: 6.23 MB
    {
      "meta" : {
        "view" : {
          "id" : "pdvh-tf2u",
          "name" : "2012 Vehicle Collisions Investigated by State Police",
          "attribution" : "Maryland State Police",
          "averageRating" : 0,
          "category" : "Public Safety",
          "createdAt" : 1367604900,
          "description" : "Collisions investigated by the Maryland State Police in 2012 (does not include collisions investigated by local jurisdictions).",
    ...