Windows下解压文件问题 [英] trouble unzipping file under Windows

查看:27
本文介绍了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 上会引发以下错误:

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?

推荐答案

?download.file 中,我们读到:

如果未提供 mode 并且 url 以 .gz、.bz2、.xz、.tgz 之一结尾,.zip、.rda 或 .RData 完成二进制传输.由于 Windows(不同于Unix-alikes)确实区分了文本和二进制文件,注意是需要使用 mode = "wb" 传输其他二进制文件类型.

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".

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

这篇关于Windows下解压文件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆