在 r 中读取一个 zip 文件

Read a zip file in r

我想从网上读取一个zip文件,我的代码如下

temp<-tempfile()
download<-download.file("http://depts.washington.edu/control/LARRY/TE/IDVs/idv1.zip",temp)
data<-read.table(unz(temp,"r.dat"),head=FALSE)
unlink(temp)

但是显示错误

Error in open.connection(file, "rt") : cannot open the connection
In addition: Warning message:
In open.connection(file, "rt") :
  cannot locate file 'r.dat' in zip file 'C:\Users\CHENGF~2\AppData\Local\Temp\RtmpgtJShr\file361c5d0a55eb'

不知道为什么不能读取数据,希望高人帮帮我!

这适用于所有 idv 文件,但 idv1 似乎已损坏。您需要使用其他工具解压 idv1.zip 并在...

中阅读
readrdat <- function(n) {
    fname <- paste0("idv",n)
    zipname <- paste0(fname,".zip")
    weblink <- paste0("http://depts.washington.edu/control/LARRY/TE/IDVs/",zipname)
    download.file(weblink,zipname)
    data <- read.table(unz(zipname,paste0(fname,"/r.dat")),header=FALSE)
    unlink(zipname)
    return(data)
} #readrdat

lsdata <- lapply(1:15, function(n) {
    tryCatch(readrdat(n), error=function(e) NULL)
})
lapply(lsdata, is.null)