Last active
July 29, 2016 21:25
-
-
Save benjamin-chan/26274cb696f25a70c4730a5c12dae682 to your computer and use it in GitHub Desktop.
Download CMS 2008-2010 Data Entrepreneurs' Synthetic Public Use File (DE-SynPUF)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getSynPUF <- function (zipFile) { | |
# [CMS 2008-2010 Data Entrepreneurs' Synthetic Public Use File (DE-SynPUF)](https://www.cms.gov/Research-Statistics-Data-and-Systems/Downloadable-Public-Use-Files/SynPUFs/DE_Syn_PUF.html) | |
# | |
# Examples: | |
# | |
# > getSynPUF("DE1_0_2008_to_2010_Carrier_Claims_Sample_1A.zip") | |
# > getSynPUF("DE1_0_2008_to_2010_Carrier_Claims_Sample_1B.zip") | |
# > getSynPUF("DE1_0_2010_Beneficiary_Summary_File_Sample_1.zip") | |
# | |
require(readr) | |
require(data.table) | |
urlStem <- "https://www.cms.gov/Research-Statistics-Data-and-Systems/Downloadable-Public-Use-Files/SynPUFs/Downloads" | |
url <- file.path(urlStem, zipFile) | |
path <- tempdir() | |
f <- tempfile() | |
download.file(url, f, mode = "wb") | |
csvFile <- as.character(unzip(f, list = TRUE)["Name"]) | |
unzip(f, files=csvFile, exdir = path) | |
D <- read_csv(file.path(path, csvFile)) | |
D <- data.table(D) | |
setnames(D, names(D), tolower(names(D))) | |
setkey(D, desynpuf_id) | |
D | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment