diff --git a/.Rhistory b/.Rhistory deleted file mode 100644 index 8e3072e..0000000 --- a/.Rhistory +++ /dev/null @@ -1,474 +0,0 @@ -library(devtools) -devtools::use_testthat() -tempfile() -download.nhanes.file <- function(file.name, year, destination = tempfile(), overwrite = TRUE) { -url <- paste0("http://wwwn.cdc.gov/nchs/nhanes/", year, '/', file.name) -# Make sure the destination folder ends in a trailing slash -lastChar <- substr(destination, nchar(destination) - 1, nchar(destination)) -if(lastChar != '/') { -lastChar <- paste0(lastChar, '/') -} -destination <- paste0(destination, file.name) -if(overwrite == FALSE) { -if(file.exists(destination) == TRUE) { -return(destination) -} -} -download.file(url, destination, method='curl', mode='w') -return(destination) -} -download.nhanes.file("HEPG_G", "2011-2012") -?file.path -file.path("C:\\Users\\susmann\\AppData\\Local\\Temp", "test") -download.nhanes.file <- function(file.name, year, destination = tempfile(), overwrite = TRUE) { -url <- paste0("http://wwwn.cdc.gov/nchs/nhanes/", year, '/', file.name) -destination <- file.path(destination, file.name) -if(overwrite == FALSE) { -if(file.exists(destination) == TRUE) { -return(destination) -} -} -download.file(url, destination, method='curl', mode='w') -return(destination) -} -download.nhanes.file("HEPG_G", "2011-2012") -download.nhanes.file("HEPG_G", "2011-2012") -download.nhanes.file("HEPG_G", "2011-2012") -?tempfile -tempdir() -download.nhanes.file <- function(file.name, year, destination = tempdir(), overwrite = TRUE) { -url <- paste0("http://wwwn.cdc.gov/nchs/nhanes/", year, '/', file.name) -destination <- file.path(destination, file.name) -if(overwrite == FALSE) { -if(file.exists(destination) == TRUE) { -return(destination) -} -} -download.file(url, destination, method='curl', mode='w') -return(destination) -} -download.nhanes.file("HEPG_G", "2011-2012") -file.path(tempdir(), "HEPG_G") -file.path(tempdir(), "HEPG_G", ".XPT") -download.nhanes.file <- function(file.name, year, destination = tempdir(), overwrite = TRUE) { -url <- paste0("http://wwwn.cdc.gov/nchs/nhanes/", year, '/', file.name) -if(grepl(".XPT", file.name) == FALSE) { -file.name <- paste0(file.name, ".XPT") -} -destination <- file.path(destination, file.name) -if(overwrite == FALSE) { -if(file.exists(destination) == TRUE) { -return(destination) -} -} -download.file(url, destination, method='curl', mode='w') -return(destination) -} -download.nhanes.file("HEPG_G", "2011-2012") -valid <- switch(year, -'2001-2002' = TRUE, -'2003-2004' = TRUE, -'2005-2006' = TRUE, -'2007-2008' = TRUE, -'2009-2010' = TRUE, -'2011-2012' = TRUE, -'2013-2014' = TRUE) -year = '2001-2002' -valid <- switch(year, -'2001-2002' = TRUE, -'2003-2004' = TRUE, -'2005-2006' = TRUE, -'2007-2008' = TRUE, -'2009-2010' = TRUE, -'2011-2012' = TRUE, -'2013-2014' = TRUE) -valid -year = 'test' -valid <- switch(year, -'2001-2002' = TRUE, -'2003-2004' = TRUE, -'2005-2006' = TRUE, -'2007-2008' = TRUE, -'2009-2010' = TRUE, -'2011-2012' = TRUE, -'2013-2014' = TRUE) -valid -?switch -valid <- switch(year, -'2001-2002' = TRUE, -'2003-2004' = TRUE, -'2005-2006' = TRUE, -'2007-2008' = TRUE, -'2009-2010' = TRUE, -'2011-2012' = TRUE, -'2013-2014' = TRUE, -FALSE) -valid -validate.year <- function(year) { -valid <- switch(year, -'2001-2002' = TRUE, -'2003-2004' = TRUE, -'2005-2006' = TRUE, -'2007-2008' = TRUE, -'2009-2010' = TRUE, -'2011-2012' = TRUE, -'2013-2014' = TRUE, -FALSE) -} -validate.year(year) -validate.year <- function(year) { -valid <- switch(year, -'2001-2002' = TRUE, -'2003-2004' = TRUE, -'2005-2006' = TRUE, -'2007-2008' = TRUE, -'2009-2010' = TRUE, -'2011-2012' = TRUE, -'2013-2014' = TRUE, -FALSE) -return(valid) -} -validate.year("2001-2002") -validate.year <- function(year, throw.error = TRUE) { -valid <- switch(year, -'1999-2000' = TRUE, -'2001-2002' = TRUE, -'2003-2004' = TRUE, -'2005-2006' = TRUE, -'2007-2008' = TRUE, -'2009-2010' = TRUE, -'2011-2012' = TRUE, -'2013-2014' = TRUE, -FALSE) -if(throw.error == TRUE && valid == FALSE) { -stop(pasteo("Invalid year: ", year)) -} -return(valid) -} -validate.year("t") -validate.year <- function(year, throw.error = TRUE) { -valid <- switch(year, -'1999-2000' = TRUE, -'2001-2002' = TRUE, -'2003-2004' = TRUE, -'2005-2006' = TRUE, -'2007-2008' = TRUE, -'2009-2010' = TRUE, -'2011-2012' = TRUE, -'2013-2014' = TRUE, -FALSE) -if(throw.error == TRUE && valid == FALSE) { -stop(paste0("Invalid year: ", year)) -} -return(valid) -} -validate.year("t") -validate.year("2011-2012") -download.nhanes.file <- function(file.name, year, destination = tempdir(), overwrite = TRUE) { -validate.year() -if(!dir.exists(destination)) { -stop(paste0("Directory doesn't exist: ", destination)) -} -url <- paste0("http://wwwn.cdc.gov/nchs/nhanes/", year, '/', file.name) -if(grepl(".XPT", file.name) == FALSE) { -file.name <- paste0(file.name, ".XPT") -} -destination <- file.path(destination, file.name) -if(overwrite == FALSE) { -if(file.exists(destination) == TRUE) { -return(destination) -} -} -download.file(url, destination, method='curl', mode='w') -return(destination) -} -download.nhanes.file("HEPG_G", "2011-2012") -download.nhanes.file <- function(file.name, year, destination = tempdir(), overwrite = TRUE) { -validate.year(year) -if(!dir.exists(destination)) { -stop(paste0("Directory doesn't exist: ", destination)) -} -url <- paste0("http://wwwn.cdc.gov/nchs/nhanes/", year, '/', file.name) -if(grepl(".XPT", file.name) == FALSE) { -file.name <- paste0(file.name, ".XPT") -} -destination <- file.path(destination, file.name) -if(overwrite == FALSE) { -if(file.exists(destination) == TRUE) { -return(destination) -} -} -download.file(url, destination, method='curl', mode='w') -return(destination) -} -download.nhanes.file("HEPG_G", "2011-2012") -download.nhanes.file("HEPG_G", "2011-2012", destination="test") -?download.file -download_nhanes_file <- function(file_name, year, destination = tempdir(), overwrite = TRUE) { -validate_year(year) -if(!dir.exists(destination)) { -stop(paste0("Directory doesn't exist: ", destination)) -} -url <- paste0("http://wwwn.cdc.gov/nchs/nhanes/", year, '/', file.name) -if(grepl(".XPT", file_name) == FALSE) { -file_name <- paste0(file_name, ".XPT") -} -destination <- file.path(destination, file_name) -if(overwrite == FALSE) { -if(file.exists(destination) == TRUE) { -return(destination) -} -} -download.file(url, destination, method='auto', mode='w') -return(destination) -} -download_nhanes_file("HEPG_G", "2011-2012") -demography_filename <- function(year) { -validate_year(year) -if(year == '1999-2000') { -return("DEMO.XPT") -} -suffix = switch(year, -'2001-2002' = 'B', -'2003-2004' = 'C', -'2005-2006' = 'D', -'2007-2008' = 'E', -'2009-2010' = 'F', -'2011-2012' = 'G', -'2013-2014' = 'H' -) -return(paste0("DEMO_", suffix, ".XPT")) -} -validate_year <- function(year, throw_error = TRUE) { -valid <- switch(year, -'1999-2000' = TRUE, -'2001-2002' = TRUE, -'2003-2004' = TRUE, -'2005-2006' = TRUE, -'2007-2008' = TRUE, -'2009-2010' = TRUE, -'2011-2012' = TRUE, -'2013-2014' = TRUE, -FALSE) -if(throw_error == TRUE && valid == FALSE) { -stop(paste0("Invalid year: ", year)) -} -return(valid) -} -download_nhanes_file <- function(file_name, year, destination = tempdir(), overwrite = TRUE) { -validate_year(year) -if(!dir.exists(destination)) { -stop(paste0("Directory doesn't exist: ", destination)) -} -url <- paste0("http://wwwn.cdc.gov/nchs/nhanes/", year, '/', file.name) -if(grepl(".XPT", file_name) == FALSE) { -file_name <- paste0(file_name, ".XPT") -} -destination <- file.path(destination, file_name) -if(overwrite == FALSE) { -if(file.exists(destination) == TRUE) { -return(destination) -} -} -download.file(url, destination, method='auto', mode='w') -return(destination) -} -load_nhanes_lab_data <- function(file_name, year, destination = tempdir(), merge_demographics = FALSE, overwrite = FALSE) { -validate_year(year) -full_path <- download_nhanes_file(file_name, year, destination, overwrite = overwrite) -dat <- read.xport(full_path) -return(dat) -} -load_nhanes_demography_data <- function(year, destination = tempdir(), overwrite = FALSE) { -validate_year(year) -full_path <- download_nhanes_file(demography_filename(year), year, destination, overwrite = overwrite) -dat <- read.xport(full_path) -return(dat) -} -download_nhanes_file("HEPG_G", "2011-2012") -download_nhanes_file <- function(file_name, year, destination = tempdir(), overwrite = TRUE) { -validate_year(year) -if(!dir.exists(destination)) { -stop(paste0("Directory doesn't exist: ", destination)) -} -url <- paste0("http://wwwn.cdc.gov/nchs/nhanes/", year, '/', file_name) -if(grepl(".XPT", file_name) == FALSE) { -file_name <- paste0(file_name, ".XPT") -} -destination <- file.path(destination, file_name) -if(overwrite == FALSE) { -if(file.exists(destination) == TRUE) { -return(destination) -} -} -download.file(url, destination, method='auto', mode='w') -return(destination) -} -download_nhanes_file("HEPG_G", "2011-2012") -download_nhanes_file <- function(file_name, year, destination = tempdir(), overwrite = TRUE) { -validate_year(year) -if(!dir.exists(destination)) { -stop(paste0("Directory doesn't exist: ", destination)) -} -if(grepl(".XPT", file_name) == FALSE) { -file_name <- paste0(file_name, ".XPT") -} -destination <- file.path(destination, file_name) -if(overwrite == FALSE) { -if(file.exists(destination) == TRUE) { -return(destination) -} -} -url <- paste0("http://wwwn.cdc.gov/nchs/nhanes/", year, '/', file_name) -download.file(url, destination, method='auto', mode='w') -return(destination) -} -download_nhanes_file("HEPG_G", "2011-2012") -download_nhanes_file <- function(file_name, year, destination = tempdir(), overwrite = TRUE) { -validate_year(year) -if(!dir.exists(destination)) { -stop(paste0("Directory doesn't exist: ", destination)) -} -if(grepl(".XPT", file_name) == FALSE) { -file_name <- paste0(file_name, ".XPT") -} -destination <- file.path(destination, file_name) -if(overwrite == FALSE) { -if(file.exists(destination) == TRUE) { -return(destination) -} -} -url <- paste0("http://wwwn.cdc.gov/nchs/nhanes/", year, '/', file_name) -download.file(url, destination, method='curl', mode='w') -return(destination) -} -download_nhanes_file("HEPG_G", "2011-2012") -download_nhanes_file <- function(file_name, year, destination = tempdir(), overwrite = TRUE) { -validate_year(year) -if(!dir.exists(destination)) { -stop(paste0("Directory doesn't exist: ", destination)) -} -if(grepl(".XPT", file_name) == FALSE) { -file_name <- paste0(file_name, ".XPT") -} -destination <- file.path(destination, file_name) -if(overwrite == FALSE) { -if(file.exists(destination) == TRUE) { -return(destination) -} -} -url <- paste0("http://wwwn.cdc.gov/nchs/nhanes/", year, '/', file_name) -download.file(url, destination, method='auto', mode='w') -return(destination) -} -download_nhanes_file("HEPG_G", "2011-2012") -download_nhanes_file <- function(file_name, year, destination = tempdir(), overwrite = TRUE) { -validate_year(year) -if(!dir.exists(destination)) { -stop(paste0("Directory doesn't exist: ", destination)) -} -if(grepl(".XPT", file_name) == FALSE) { -file_name <- paste0(file_name, ".XPT") -} -destination <- file.path(destination, file_name) -if(overwrite == FALSE) { -if(file.exists(destination) == TRUE) { -return(destination) -} -} -url <- paste0("http://wwwn.cdc.gov/Nchs/Nhanes/", year, '/', file_name) -download.file(url, destination, method='auto', mode='w') -return(destination) -} -download_nhanes_file("HEPG_G", "2011-2012") -download_nhanes_file("HEPA_G", "2011-2012") -demography_filename("2011-2012") -demography_filename("1999-2000") -demography_filename("1999-20002") -load_nhanes_lab_data <- function(file_name, year, destination = tempdir(), merge_demographics = FALSE, overwrite = FALSE) { -validate_year(year) -full_path <- download_nhanes_file(file_name, year, destination, overwrite = overwrite) -dat <- read.xport(full_path) -return(dat) -} -load_nhanes_lab_data("UHM_G", "2011-2012") -devtools::use_package("foreign") -devtools::use_package("survey") -library(RNHANES) -library(RNHANES) -validate_year("2011-2012") -demography_filename("2011-2012") -download_nhanes_file("HEPA_G", "2011-2012") -load_nhanes_lab_data("HEPA_G", "2011-2012") -devtools::document() -devtools::document() -devtools::document() -load_nhanes_demography_data("2011-2012") -library(RNHANES) -load_nhanes_demography_data("2011-2012") -library(RNHANES) -library(RNHANES) -load_nhanes_demography_data("2011-2012") -library(RNHANES) -load_nhanes_demography_data("2011-2012") -library(RNHANES) -load_nhanes_demography_data("2011-2012") -read.xport("C:\Users\susmann\AppData\Local\Temp\RtmpW0egpT/DEMO_G.XPT") -read.xport("C:\\Users\\susmann\\AppData\\Local\\Temp\\RtmpW0egpT/DEMO_G.XPT") -library(foreign) -read.xport("C:\\Users\\susmann\\AppData\\Local\\Temp\\RtmpW0egpT/DEMO_G.XPT") -library(RNHANES) -read.xport("C:\\Users\\susmann\\AppData\\Local\\Temp\\RtmpW0egpT/DEMO_G.XPT") -load_nhanes_demography_data("2011-2012") -test <- load_nhanes_demography_data("2011-2012") -load_nhanes_demography_data("2011-2012") -test <- load_nhanes_demography_data("2011-2012", overwrite = TRUE) -read.xport("C:\\Users\\susmann\\AppData\\Local\\Temp\\RtmpYzLB61/DEMO_G.XPT") -read.xport("C:\\Users\\susmann\\AppData\\Local\\Temp\\RtmpW0egpT/DEMO_G.XPT") -download.file -?download.file -library(RNHANES) -test <- load_nhanes_demography_data("2011-2012", overwrite = TRUE) -test -load_nhanes_demography_data("2011-2012", overwrite = TRUE) -library(RNHANES) -devtools::document() -devtools::document() -setwd("C:/Users/susmann/Dropbox/RNHANES") -devtools::document() -library(RNHANES) -?load_nhanes_lab_data -load_nhanes_data <- function(file_name, year, destination = tempdir(), merge_demographics = FALSE, overwrite = FALSE) { -validate_year(year) -full_path <- download_nhanes_file(file_name, year, destination, overwrite = overwrite) -dat <- read.xport(full_path) -if(merge_demographics == FALSE) { -demography_data <- load_nhanes_demography_data(year, destination = destination, overwrite = overwrite) -dat <- merge.data.with.demographics(demography_data, dat) -} -return(dat) -} -devtools::document() -library(RNHANES) -library(RNHANES) -load_nhanes_data("EPH_E", "2007-2008") -library(RNHANES) -load_nhanes_data("EPH_E", "2007-2008") -with_demo <- load_nhanes_data("EPH_E", "2007-2008", merge_demographics = TRUE) -head(with_demo) -"SEQN" %in% names(with_demo) -"SEQN1" %in% names(with_demo) -library(RNHANES) -devtools::document() -library(RNHANES) -?load_nhanes_demography_data -devtools::document() -library(RNHANES) -?load_nhanes_data -library(RNHANES) -load_nhanes_data("EPH_G", "2011-2012") -devtools::document() -library(RNHANES) -load_nhanes_data("EPH_G", "2011-2012", demographics = TRUE) -install_github("silentspringinstitute/RNHANES") -install_github("silentspringinstitute/RNHANES") diff --git a/.gitignore b/.gitignore index bc77c15..f7b70de 100644 --- a/.gitignore +++ b/.gitignore @@ -4,33 +4,23 @@ ehthumbs.db # Folder config file Desktop.ini - # Recycle Bin used on file shares $RECYCLE.BIN/ - # Windows Installer files *.cab *.msi *.msm *.msp - # Windows shortcuts *.lnk - # ========================= # Operating System Files -# ========================= - # OSX -# ========================= - .DS_Store .AppleDouble .LSOverride - # Thumbnails ._* - # Files that might appear in the root of a volume .DocumentRevisions-V100 .fseventsd @@ -38,13 +28,16 @@ $RECYCLE.BIN/ .TemporaryItems .Trashes .VolumeIcon.icns - # Directories potentially created on remote AFP share .AppleDB .AppleDesktop Network Trash Folder Temporary Items .apdisk - -.Rbuildignore .Rproj.user +inst/doc + +vignettes/introduction_cache +RNHANES.Rproj +.Rhistory +.Rdata diff --git a/RNHANES.Rproj b/RNHANES.Rproj deleted file mode 100644 index 398aa14..0000000 --- a/RNHANES.Rproj +++ /dev/null @@ -1,20 +0,0 @@ -Version: 1.0 - -RestoreWorkspace: Default -SaveWorkspace: Default -AlwaysSaveHistory: Default - -EnableCodeIndexing: Yes -UseSpacesForTab: Yes -NumSpacesForTab: 2 -Encoding: UTF-8 - -RnwWeave: knitr -LaTeX: pdfLaTeX - -AutoAppendNewline: Yes -StripTrailingWhitespace: Yes - -BuildType: Package -PackageUseDevtools: Yes -PackageInstallArgs: --no-multiarch --with-keep.source