2

我正在尝试从 BLS 服务器下载大量 xls 文件。当我手动下载任何文件时,它们会完美打开。

但是当我尝试从 R 内部下载文件时:

library(readxl)

tp <- "http://www.bea.gov/histdata/Releases/GDP_and_PI/2014/Q4/Third_March-27-2015/Section1ALL_Hist.xls"
temp <- paste0(tempfile(), ".xls")
download.file(tp, destfile = temp, mode = "wb")

这会下载正确大小的文件,但会尝试读取该文件:

 data <- read_excel(path = temp, sheet = 1)

返回错误

seek: wanted to seek to sector 5374034 (0x520052) loc=2751505920
4

1 回答 1

3

Set mode="wb" to do a binary transfer:

download.file(tp, destfile=temp, mode="wb")
于 2015-05-24T16:50:00.983 回答