One of the great things that I am learning about R is that it is really powerful as a data management tool. I just found how to unzip files. I could use Python for this in SPSS, but it just feels like it is more natural to do in R. Of course, you have to change the paths and the file names, but you should get the hint.
Note: Right now, this works on .zip files. I wonder if other formats will work as well?
Also: I use Eclipse and StatET to develop my R code. Here is some help at Jeromy’s blog to get you up and running here.
Lastly: Thanks to Hadley Wickham for the help on how to search an entire directory using regex @hadleywickham
## Look at your current directory
## and set it to what you want it to be
## need forward slash on windows!!
setwd("C:/Users/Brock/Documents/IPEDS/ENROLLMENT - Migration/")
## get help on zipfiles
## create a vector file names we want to extract from
files.temp <- c("EF2008C.zip","EF2006C.zip","EF2004C.zip","EF2002C.zip","EF2000C.zip","EF98_C.zip","EF1988_C.zip")
## create a loop to extract the files to the directory set above
## will build the file name of the extracted file
for (i in files.temp)
## a quicker way that doesnt require that you know which files - just does all
## \ allows you to use the . in .zip, the . is a special character
## $ is tells the pattern to search is the end? not sure about this one
for (i in dir(pattern="\.zip$"))
## clean up the memory and close
Filed under: How-to, R Tagged: R, rstats, unzip