################################################################################## ################################################################################## # an example R script to create a file with lots of wget commands to retrieve online # data (or, alternatively, curl commands on a Mac) # After running this script in R, in the Unix command line, type # chmod +x myget.txt # ./myget.txt # # Author: Sherry Towers # smtowers@asu.edu # Created: Jan 29th, 2013 # # Copyright Sherry Towers, 2013 # # This script is not guaranteed to be free of bugs and/or errors. # # This script can be freely used and shared, as long as the author information # and copyright in the header remains intact. ################################################################################## lmac = 1 # set to zero if Unix, but not Mac ######################################################################## # make a wget file for the CDC influenza data ######################################################################## sink("myget.txt") vyear = seq(1997,2011,1) for (i in 1:(length(vyear)-1)){ for (j in 1:10){ fname = paste("http://www.cdc.gov/flu/weekly/regions",vyear[i],"-",vyear[i+1],"/datafinalHHS/whoreg",j,".csv",sep="") fnameb = paste("whoreg",j,"_",vyear[i],"_",vyear[i+1],".txt",sep="") cat("sleep 5\n") # when accessing data like this, it is polite to not hammer the website with # rapid repeated requests... the sleep command puts a few seconds pause between commands if (lmac){ cat("curl ",fname,"-o",fnameb,"\n") }else{ cat("wget ",fname,"\n") } } } sink()