1

尝试使用 R 从 cdc 下载此压缩文件。它在 firefox 上运行良好。所以我setInternet2(TRUE)立即尝试,但仍然没有用。

在以下每种情况下,我得到:

z<-解压缩(tf)

Warning message:
In unzip(tf) : zip file is corrupt

这是我所有尝试的开始两行 -

fn <- 'ftp://ftp.cdc.gov/pub/health_statistics/nchs/datasets/dvs/natality/nat2012us.zip'
tf <- tempfile() ; td <- tempdir()

这就是我尝试过的:

# fails
download.file(fn,tf,mode='wb')
z <- unzip( tf , exdir = td )

# fails
setInternet2(TRUE)
download.file(fn,tf,mode='wb')
z <- unzip( tf , exdir = td )

# fails
download.file(fn,tf,mode='wb',cacheOK=FALSE)
z <- unzip( tf , exdir = td )

# fails
setInternet2(TRUE)
download.file(fn,tf,mode='wb',cacheOK=FALSE)
z <- unzip( tf , exdir = td )

# fails
library(downloader)
download(fn,tf,mode='wb')
z <- unzip( tf , exdir = td )

# fails
library(httr)
resp <- GET(fn)
writeBin(content(resp, "raw"), tf)

# fails
library(RCurl)
x <- getBinaryURL( fn )
writeBin( x , tf )
z <- unzip(tf)


# in every case:
> file.info(tf)$size
[1] 228799759

抱歉,如果这是愚蠢的事情

4

1 回答 1

2

看起来windowsunzip="internal"是问题所在。 shell()和 winrar 解决这个问题

fn <- 'ftp://ftp.cdc.gov/pub/health_statistics/nchs/datasets/dvs/natality/nat2012us.zip'
tf <- tempfile()
download.file( fn , tf , mode = 'wb' )

wr <- normalizePath( "C:/Program Files/WinRAR/WinRAR.exe" )

td <- tempdir()
shell( paste0( '"' , wr , '" x ' , tf , ' ' , td ) )
于 2014-04-19T10:32:32.697 回答