Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Download and save all Global Burden of Disease data from IHME as compressed RDS or raw CSV files. Accounts for some countries with different URLs. Updated 4/8/2015 to make downloads more flexible.
library(data.table)
library(plyr)
library(httr)
library(reshape2)
#specify the location to save download files
#pathToGBDDataStore <- "c:/path/to/main/dir"
pathToGBDDataStore <-'~/Desktop/gbd'
###########################################
# Download and save GBD data #
###########################################
countryList <- c("AFG","AGO","ALB","AND","ARE","ARG","ARM","ATG","AUS","AUT","AZE","BDI","BEL","BEN","BFA","BGD","BGR","BHR","BHS","BIH","BLR","BLZ","BOL","BRA","BRB","BRN","BTN","BWA","CAF","CAN","CHE","CHL","CHN","CIV","CMR","COD","COG","COL","COM","CPV","CRI","CUB","CYP","CZE","DEU","DJI","DMA","DNK","DOM","DZA","ECU","EGY","ERI","ESP","EST","ETH","FIN","FJI","FRA","FSM","GAB","GBR","GEO","GHA","GIN","GMB","GNB","GNQ","GRC","GRD","GTM","GUY","HND","HRV","HTI","HUN","IDN","IND","IRL","IRN","IRQ","ISL","ISR","ITA","JAM","JOR","JPN","KAZ","KEN","KGZ","KHM","KIR","KOR","KWT","LAO","LBN","LBR","LBY","LCA","LKA","LSO","LTU","LUX","LVA","MAR","MDA","MDG","MDV","MEX","MHL","MKD","MLI","MLT","MMR","MNE","MNG","MOZ","MRT","MUS","MWI","MYS","NAM","NER","NGA","NIC","NLD","NOR","NPL","NZL","OMN","PAK","PAN","PER","PHL","PNG","POL","PRK","PRT","PRY","PSE","QAT","ROU","RUS","RWA","SAU","SDN","SEN","SGP","SLB","SLE","SLV","SOM","SRB","STP","SUR","SVK","SVN","SWE","SWZ","SYC","SYR","TCD","TGO","THA","TJK","TKM","TLS","TON","TTO","TUN","TUR","TWN","TZA","UGA","UKR","URY","USA","UZB","VCT","VEN","VNM","VUT","WSM","YEM","ZAF","ZMB","ZWE")
#download and clean all GBD files
#check if URL okay and proceed
#can save as RDS or CSV
GBDgrab <- function(x, saveRDS=T, saveCSV=F){
url <- paste('http://ghdx.healthmetricsandevaluation.org/sites/default/files/record-attached-files/IHME_',x,'_GBD_2010_RESULTS_1990_2010_BY_CAUSE_Y2013M08D29.CSV',sep="")
alt_url <- paste('http://ghdx.healthmetricsandevaluation.org/sites/default/files/record-attached-files/IHME_',x,'_GBD_2010_RESULTS_1990_2010_BY_CAUSE_Y2013M08D29_0.CSV',sep="")
if(url_ok(url)){
temp <- fread(paste(url))
}else if(url_ok(alt_url)){
temp <- fread(paste(alt_url))
}
temp[,cause_name:=NULL]
temp[,cause_medium:=NULL]
#creates directory specified previously; does not overwrite
dir.create(file.path(pathToGBDDataStore), showWarnings=F)
if(saveRDS){
saveRDS(temp,file=paste(file.path(pathToGBDDataStore),'/',x,'.rds',sep=""))
}
if(saveCSV){
write.csv(temp,file=paste(file.path(pathToGBDDataStore),'/',x,'.csv',sep=""), row.names=F)
}
}
l_ply(countryList,GBDgrab)
@ajaypillarisetti

This comment has been minimized.

Copy link
Owner Author

commented Feb 14, 2014

Annoyance: the url changed from /sites/ghdx to /sites/default

@ajaypillarisetti

This comment has been minimized.

Copy link
Owner Author

commented Apr 8, 2015

Updated to make more flexible:

  • user specifies download location
  • user specifies RDS vs CSV
@ajaypillarisetti

This comment has been minimized.

Copy link
Owner Author

commented May 4, 2016

Major annoyance: this data is no longer available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.