Skip to content

Instantly share code, notes, and snippets.

@stevebargelt
Created July 26, 2014 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevebargelt/f25dd4ca1956e3cc8630 to your computer and use it in GitHub Desktop.
Save stevebargelt/f25dd4ca1956e3cc8630 to your computer and use it in GitHub Desktop.
Default Data Download Snippet in R
#Change the working directory
setwd("~/Google Drive/code/ThisProject")
# Change these three variables
datapath <- "./data"
filename <- "housing.csv"
fileUrl <- "http://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06hid.csv"
######
if (!file.exists(datapath)) {
dir.create(datapath)
}
pathandfilename <- paste(datapath, "/", filename, sep="")
if (!file.exists(pathandfilename)) {
download.file(fileUrl, destfile=pathandfilename, method="curl")
}
data <- read.csv(pathandfilename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment