使用R下载并解压缩包含文件夹的zip文件

时间:2016-04-03 12:05:10

标签: r

在Rstudio中我写道:

urlcoP <- "http://www.cophieu68.vn/datax123456/metastock_all_data.zip"
temp <- tempfile()
download.file(urlcoP,temp)
data <- read.table(unz(temp, "metastock_all_data.txt"))

但是它得到了错误:

Error in open.connection(file, "rt") : cannot open the connection
In addition: Warning message:
In open.connection(file, "rt") :
  cannot locate file 'metastock_all_data.txt' in zip file 'C:\TEMP\RtmpaaH3PW\file135c1e97348'

原因是metastock_all_data.txt位于zip中名为datax123456的文件夹中。

1 个答案:

答案 0 :(得分:2)

试试这个吗?

data <- read.table(unz(temp, "datax123456/metastock_all_data.txt"))

metastock_all_data.txt位于zip中名为datax123456的文件夹中,因此在metastock_all_data.txt之前添加文件夹