2011-08-22 96 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

見編輯...... –