-1

I am having some problem with the weatherData package in R. As I am using this code:

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")

I am getting this error:

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

After I searched a bit, I came to know maybe its due to RCurl package not being installed in my R version of 3.2.1. But as I started installing RCurl, I got this:

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

I am using Ubuntu 14.04. Can anyone help me out?

Monali
  • 43
  • 7
  • 1
    You shouldn't need to do that. Just use `read.csv()` with the url, removing the call to `url()` as well. So try `read.csv("http://...")`. – Rich Scriven May 27 '16 at 07:43
  • Still getting the same error! @RichardScriven – Monali May 27 '16 at 08:00
  • It works fine for me on R 3.3.0 and using `read.csv("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")` – Rich Scriven May 27 '16 at 08:01
  • Oh...my R version is 3.2.2. Do you think this might be the issue? – Monali May 27 '16 at 08:02
  • Oh and can you tell me about the RCurl package. It ain't getting installed. @RichardScriven – Monali May 27 '16 at 08:04
  • Install RCurl by running `sudo apt-get install r-cran-rcurl` – xxfelixxx May 27 '16 at 08:15
  • Using this I get this error: E: encountered a section with no package: header E: Problem with MergeList /var/lib/apt/list/us.archive.ubuntu.com_ubuntu_dists_trusty_universe_i18n_Translation-en E: The package lists or status file could not be parsed or opened. @xxfelixxx – Monali May 27 '16 at 08:29
  • Look here for MergeList issue: http://askubuntu.com/questions/30072/how-do-i-fix-a-problem-with-mergelist-or-status-file-could-not-be-parsed-err – xxfelixxx May 27 '16 at 08:35
  • Are you sure that `libcurl` is installed? Maybe try `sudo apt-get install libcurl3` in a linux terminal... – RHertel May 27 '16 at 10:33
  • Yeah, libcurl3 is already installed. @RHertel – Monali May 27 '16 at 13:23

1 Answers1

0

A simpler approach using plain old curl since the url content is not csv but actually html, then cleaning up the html, then loading it in 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

The content has trailing <br > markup

$ 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 />

Lets eliminate this markup and turn this into csv.

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

Now load it as usual in 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"       
xxfelixxx
  • 6,512
  • 3
  • 31
  • 38