Binh Tran Van
Binh Tran Van

Reputation: 39

Using R to Download and extract zip file that contains a folder

In Rstudio I wrote:

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

But it's get the error:

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'

The reason is that the metastock_all_data.txt is in a folder called datax123456 in the zip.

Upvotes: 1

Views: 1935

Answers (1)

chinsoon12
chinsoon12

Reputation: 25225

try this?

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

metastock_all_data.txt is in a folder called datax123456 in the zip, hence add the folder before metastock_all_data.txt

Upvotes: 3

Related Questions