无法安装包RCurl

时间:2016-05-27 07:35:50

标签: r ubuntu-14.04 packages rcurl install.packages

我在使用R中的weatherData包时遇到了一些问题。我正在使用此代码:

a <- read.csv(url("http://www.wunderground.com/history/airport/sfo/2016/1/1/CustomHistory.html?dayend=27&monthend=5&yearend=2016&req_city=NA&req_state=NA&req_statename=NA&format=1"), 
                  method ="libcurl")

我收到此错误:

Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
  unused argument (method = "libcurl")

在我搜索了一下之后,我开始知道可能是因为我的R版本3.2.1中没有安装RCurl包。但是当我开始安装RCurl时,我得到了这个:

Cannot find curl-config
ERROR: configuration failed for package ‘RCurl’
* removing ‘/home/dell/R/x86_64-pc-linux-gnu-library/3.2/RCurl’
Warning in install.packages :
  installation of package ‘RCurl’ had non-zero exit status

我使用的是Ubuntu 14.04。 任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

使用普通旧curl的简单方法,因为网址内容不是csv,而是实际html,然后清理html,然后将其加载到R:

$ curl 'https://www.wunderground.com/history/airport/sfo/2016/1/1/CustomHistory.html?dayend=27&monthend=5&yearend=2016&req_city=NA&req_state=NA&req_statename=NA&format=1' \ 
        > data.html

内容尾随<br >标记

$ head -n 3 data.html 

PDT,Max TemperatureC,Mean TemperatureC,Min TemperatureC,DewPointC,MeanDew PointC,Min DewpointC,Max Humidity, Mean Humidity, Min Humidity, Max Sea Level PressurehPa, Mean Sea Level PressurehPa, Min Sea Level PressurehPa, Max VisibilityKm, Mean VisibilityKm, Min VisibilitykM, Max Wind SpeedKm/h, Mean Wind SpeedKm/h, Max Gust SpeedKm/h,Precipitationmm, CloudCover, Events,WindDirDegrees<br />

2016-1-1,9,6,3,0,-3,-6,76,57,38,1023,1021,1020,16,16,16,27,14,32,0.00,3,,90<br />

让我们删除此标记并将其转换为csv。

$ cat data.html | perl -lpe 's|<br.*$||;' > data.csv

现在像往常一样在R

中加载它
$ R

d <- read.csv('data.csv')

colnames(d)

 [1] "PDT"                        "Max.TemperatureC"          
 [3] "Mean.TemperatureC"          "Min.TemperatureC"          
 [5] "Dew.PointC"                 "MeanDew.PointC"            
 [7] "Min.DewpointC"              "Max.Humidity"              
 [9] "Mean.Humidity"              "Min.Humidity"              
 [11] "Max.Sea.Level.PressurehPa"  "Mean.Sea.Level.PressurehPa"
 [13] "Min.Sea.Level.PressurehPa"  "Max.VisibilityKm"          
 [15] "Mean.VisibilityKm"          "Min.VisibilitykM"          
 [17] "Max.Wind.SpeedKm.h"         "Mean.Wind.SpeedKm.h"       
 [19] "Max.Gust.SpeedKm.h"         "Precipitationmm"           
 [21] "CloudCover"                 "Events"                    
 [23] "WindDirDegrees"