2016-03-07 46 views
0

下載我試圖讓我的研究可重複在figshare存儲數據損壞的zip文件。當我下載並解壓在R.數據
here is the zip
如果我手動下載它,它會打開OK
奇怪的事情發生;但是當我嘗試使用R腳本獲取它時,下載的存檔文件已損壞。任何想法是哪裏的問題?R&figshare:當R中


的代碼重現我的錯誤

url <- 'https://ndownloader.figshare.com/files/4797355' 
path <- 'test/missing_data_raw.zip' 

ifelse(file.exists(path1), yes = 'file alredy exists', no = download.file(url1, path1)) 

unzip(zipfile = path1,exdir = 'test') 
+0

你分配的'ifelse()'價值'path1' ? – effel

+0

你可以試試'download.file(URL,路徑,方法= 「wget的」)'或'下載(網址,路徑,方法= 「捲曲」)' – fishtank

+0

@fishtank無論'方法= 「wget的」''也沒有方法= 「捲曲」幫助。但'mode ='wb''完成了這個訣竅。感謝您的好意! – ikashnitsky

回答

2

嘗試將下載模式,明確二進制:

url <- 'https://ndownloader.figshare.com/files/4797217' 
path1 <- tempfile(fileext = ".zip") 
if (file.exists(path1)) 'file alredy exists' else download.file(url, path1, mode="wb") 
unzip(zipfile = path1,exdir = tempdir()) 
+0

謝謝! 'mode =「wb」'訣竅 – ikashnitsky