2011-08-22 50 views
18

我想下载并打开R中的下列tar.gz文件:在R中解压tar.gz文件?

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

是否有可以完成这个命令?

谢谢。

+0

看看'?untar' – James

+1

可能重复? http://stackoverflow.com/questions/3053833/using-r-to-download-zipped-data-file-extract-and-import-data – joran

+1

另一个重复? http://stackoverflow.com/questions/7044808/using-r-to-download-gzipped-data-file-extract-and-import-data/7045059#7045059 – Ramnath

回答

29
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") 

随口说说,我不知道的方式,以达到进入tar文件并阅读相应CSV文件,而不拆包...

+0

也可以解压一个tarball里面的特定文件吗?我认为'untar'中的'files'参数可以做到这一点,但我不确定如何?帮助赞赏.. – Ashwin

+2

见编辑...... –