Windows下无法解压缩文件

问题描述 投票:1回答:1

我有以下代码:

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

您碰巧知道出了什么问题吗?

r unzip
1个回答
2
投票

?download.file中,我们读到:

如果未提供mode,并且网址以.gz,.bz2,.xz,.tgz中的一个结尾,.zip,.rda或.RData完成二进制传输。由于Windows(不同于Unix-likes)确实区分文本文件和二进制文件,注意需要使用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
© www.soinside.com 2019 - 2024. All rights reserved.