我对R编程比较陌生。我正在尝试使用URL下载一些包含CSV文件的zip文件并阅读它们。以下是代码,URL和错误。从错误中我怀疑它只是下载一些文本或HTML代码,而不下载ZIP文件(网站上显示的ZIP文件下载仅为10KB,而ZIP文件的下载为396KB)。我尝试从同一站点下载其他一些数据集,但是存在相同的问题。感谢有人可以提供帮助。请注意,我可以直接下载ZIP文件,提取并查看CSV文件。
tempdl <- tempfile()
download.file("https://www.kaggle.com/russellyates88/suicide-rates-overview-1985-to-2016/downloads/suicide-rates-overview-1985-to-2016.zip",tempdl, mode="wb")
unzip(tempdl, "master.csv")
data <- read.table("master.csv", sep=",")
我得到的错误是:
> download.file("https://www.kaggle.com/russellyates88/suicide-rates-overview-1985-to-2016/downloads/suicide-rates-overview-1985-to-2016.zip",tempdl, mode="wb")
trying URL 'https://www.kaggle.com/russellyates88/suicide-rates-overview-1985-to-2016/downloads/suicide-rates-overview-1985-to-2016.zip'
Content type 'text/html; charset=utf-8' length unknown
downloaded 10 KB
> unzip(tempdl, "master.csv")
Warning message:
In unzip(tempdl, "master.csv") : error 1 in extracting from zip file
> data <- read.table("master.csv", sep=",")
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'master.csv': No such file or directory