Read Compressed Zip Files in R

June 25, 2010

(This article was first published on Brock's Data Adventure » R, and kindly contributed to R-bloggers)

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("","","","","","","")

## 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

To leave a comment for the author, please follow the link and comment on their blog: Brock's Data Adventure » R. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , ,

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)