问题
I have the following code:
download.file(
"http://www.wikipathways.org//wpi/batchDownload.php?species=Homo%20sapiens&fileType=txt",
destfile="human.zip")
files <- unzip( "human.zip", list=T)
It works on Linux, but throws the following error on Windows:
Error in unzip("human.zip", list = T) :
error -103 with zipfile in unzGetCurrentFileInfo
Do you happen to know what's the problem?
回答1:
In ?download.file
, we read that:
If
mode
is not supplied and url ends in one of .gz, .bz2, .xz, .tgz, .zip, .rda or .RData a binary transfer is done. Since Windows (unlike Unix-alikes) does distinguish between text and binary files, care is needed that other binary file types are transferred with mode = "wb".
Note that this list does not include .zip
, although it is a binary file type. So you need to pass mode="wb"
.
I cannot reproduce your example, but it solved my identical problem. Here is an example:
url <- "https://www.bls.gov/cex/pumd/ce_pumd_interview_diary_dictionary.xlsx"
download.file(url, 'file1.xlsx')
download.file(url, 'file2.xlsx', mode="wb") # Try this instead
library(readxl)
read_xlsx('file1.xlsx', sheet='Variables') # Fails
# Error in sheets_fun(path) :
# Evaluation error: error -103 with zipfile in unzGetCurrentFileInfo
read_xlsx('file2.xlsx', sheet='Variables') # Works
# A tibble: 3,580 x 13
来源:https://stackoverflow.com/questions/30892505/trouble-unzipping-file-under-windows