9.2 Downloading a .csv file using getURL()

The package RCurl provides functions for accessing online material. First we need the package

install.packages("RCurl", dependencies = TRUE) # [ ]

As always, once we install a package we need to really install it with library(). (You might see some red text as RCurl loads up some of its dependencies)

library(RCurl) # [ ]

We then use the getURL() to prep the info we need for downloading that .csv we want.

The file we want is “eaglesWV.csv”. It is located at this rather long URL: https://raw.githubusercontent.com/brouwern/wildlifeR/master/inst/extdata/eaglesWV.csv

First, we’ll use the “<-” assignment operator to store the shortened URL in an R object. Be sure to put the URL in quotes.

eaglesWV.url <- "https://raw.githubusercontent.com/brouwern/wildlifeR/master/inst/extdata/eaglesWV.csv" # [ ]

Next we’ll use the getURL() function to set things up, storing the info in a new object “eaglesWV.url_2” (note the “_2" on the end).

First, get the URL from the URL-containing object we just made.

eaglesWV.url_2 <- getURL(eaglesWV.url)

Now use read.csv() to actually get it.

eaglesWV_2 <- read.csv(text = eaglesWV.url_2)

We can preview the downloaded dataset using summary() or any other command we want

summary(eaglesWV_2)
##       year            WV        
##  Min.   :1980   Min.   : 0.000  
##  1st Qu.:1994   1st Qu.: 4.000  
##  Median :2001   Median : 5.000  
##  Mean   :2001   Mean   : 6.882  
##  3rd Qu.:2008   3rd Qu.:10.000  
##  Max.   :2015   Max.   :19.000  
##                 NA's   :12