1

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.

alfakini
  • 4,635
  • 2
  • 26
  • 35

1 Answers1

3

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

chinsoon12
  • 25,005
  • 4
  • 25
  • 35
  • Please explain how your answer solves the problem, it will help everyone understand your solution with more clarity and for future reference. – Aziz Apr 04 '16 at 02:16
  • I guess @chinsoon12 has defined the zip file location first, that was missing and creating error previously. – bim Apr 04 '16 at 03:01
  • Your code is not fire in Rstudio, and i find a solution of it by run the code: data <- read.csv(unzip(temp),header = TRUE, stringsAsFactors = FALSE) – Binh Tran Van Apr 05 '16 at 13:09