Description Usage Arguments Examples
View source: R/download_files.R
This function selects the proper download function to use for each type of file, data and mortality.
1 | download_nhanes(ftp_url, setup, ...)
|
ftp_url |
A specific URL to be downloaded via FTP and converted to an R dataframe |
setup |
The list object from running nhanes_setup with the details needed for naming and saving the files |
... |
To pass options to the download function (which wraps download.file()). Also can set console = FALSE to skip messages for download progress, which is useful when running parallel. When FALSE, invisibly returns the status of the download, which is later reported by the foreach package after all downloads have completed. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ## Not run:
# Example of basic download using a loop across all of the ftp download URLs.
# In this example, n is the object created by the function setup_nhanes() and
# filenames is created from teh function get_nhanes_filenames()
for(file in filenames){
download_nhanes(file, n)
}
# Example of parallel download process
# Not quite twice as fast (on my computer)
# Returns a list of completed files at the end. Set console = FALSE in above functions.
# Need to use foreach syntax for nested loops to redo above in completely parallel fashion (not shown)
library(foreach)
library(doMC) # use library(doSNOW) on Windows
registerDoMC(cores = 4) # set number of cores for your computer
foreach(file = filenames, .packages = c("foreign", "downloader"), .combine = rbind) %dopar% {
download_nhanes(file, n, console = FALSE)
}
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.