在 Windows 下解压缩文件时遇到问题
trouble unzipping file under Windows
我有以下代码:
download.file(
"http://www.wikipathways.org//wpi/batchDownload.php?species=Homo%20sapiens&fileType=txt",
destfile="human.zip")
files <- unzip( "human.zip", list=T)
它适用于 Linux,但在 Windows 上抛出以下错误:
Error in unzip("human.zip", list = T) :
error -103 with zipfile in unzGetCurrentFileInfo
你知道问题出在哪里吗?
在?download.file
中,我们读到:
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".
请注意,此列表不包括 .zip
,尽管它 是 二进制文件类型。所以你需要通过 mode="wb"
.
我无法重现你的例子,但它解决了我同样的问题。这是一个例子:
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
我有以下代码:
download.file(
"http://www.wikipathways.org//wpi/batchDownload.php?species=Homo%20sapiens&fileType=txt",
destfile="human.zip")
files <- unzip( "human.zip", list=T)
它适用于 Linux,但在 Windows 上抛出以下错误:
Error in unzip("human.zip", list = T) :
error -103 with zipfile in unzGetCurrentFileInfo
你知道问题出在哪里吗?
在?download.file
中,我们读到:
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".
请注意,此列表不包括 .zip
,尽管它 是 二进制文件类型。所以你需要通过 mode="wb"
.
我无法重现你的例子,但它解决了我同样的问题。这是一个例子:
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