【发布时间】:2020-01-20 12:30:02
【问题描述】:
我正在尝试在 R 中读取以下文件
当我将 url 直接粘贴到浏览器中时它可以工作,但由于某种原因,当它通过 R 下载时它无法打开。
我已经尝试了 download.file() 及其所有可接受的方法('lib-curl/internal/wininet/...')
u <- 'https://www.ssga.com/us/en/individual/etfs/library-content/products/fund-data/etfs/us/holdings-daily-us-en-xop.xlsx'
download.file(u)
下载的文件无法手动打开,也无法通过 readxl::read_xlsx() 或 gdata::read.xls() 在 R 中打开
我也尝试过 httr 包,但似乎不支持内容类型“xlsx:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet”。 但是我确实了解到该文件似乎已被 gzip 压缩,但我什至不确定这是否是问题
response <- httr:Get(u)
response$headers$`content-encoding`
"gzip"
有人可以建议我如何在 R 中下载这些数据吗?
【问题讨论】: