unzip a tar.gz file?

Tal Galili picture Tal Galili · Aug 22, 2011 · Viewed 36.8k times · Source

I wish to download and open the following tar.gz file in R:

http://s.wordpress.org/resources/survey/wp2011-survey.tar.gz

Is there a command which can accomplish this?

Answer

Ben Bolker picture Ben Bolker · Aug 22, 2011
fn <- "http://s.wordpress.org/resources/survey/wp2011-survey.tar.gz"
download.file(fn,destfile="tmp.tar.gz")
untar("tmp.tar.gz",list=TRUE)  ## check contents
untar("tmp.tar.gz")
## or, if you just want to extract the target file:
untar("tmp.tar.gz",files="wp2011-survey/anon-data.csv")
X <- read.csv("wp2011-survey/anon-data.csv")

Offhand, I don't know of a way to reach into the tar file and read the appropriate csv file without unpacking it ...