【问题标题】:Can not download Excel and DataBase in R but CSV works无法在 R 中下载 Excel 和数据库,但 CSV 有效
【发布时间】:2019-11-13 04:56:36
【问题描述】:

我正在经历“R 适合所有人”,在 6.2 上它要求在线下载一个 excel 文件。当他们要求下载 CSV 时,我能够做到,但我收到 Excel 的错误消息。

下载 CSV 在线作品,Excel 无法使用。几页后我尝试做数据库部分,但仍然存在一些问题。我相信我已经下载了所有软件包,但也许我遗漏了一些东西。

这是我正在使用的代码:

download.file(url='http://jaredlander.com/data/ExcelExample.xlsx', destfile = 'data/ExcelExample.xlsx', method = 'curl')

download.file("http://www.jaredlander.com/data/diamonds.db", destfile = "data\diamonds.db",mode ='wb')

我希望它下载 Excel 文件,但我收到了以下错误消息。

警告:创建文件数据失败/ExcelExample.xlsx:没有这样的 文件或警告:目录 100 254 100 254 0 0 537
0 --:--:-- --:--:-- --:--:-- 538 curl: (23) 书写体失败 (0 != 254) 下载文件中的错误(url = "http://jaredlander.com/data/ExcelExample.xlsx", : 'curl' 调用了 非零退出状态

数据库部分也是如此。

1: In download.file("http://www.jaredlander.com/data/diamonds.db",  :
  URL http://www.jaredlander.com/data/diamonds.db: cannot open destfile 'data/diamonds.db', reason 'No such file or directory'
2: In download.file("http://www.jaredlander.com/data/diamonds.db",  :
  download had nonzero exit status

【问题讨论】:

  • 您是否可能没有本地data 目录?
  • 嗨,请删除method = 并告诉我结果。 download.file(url='http://jaredlander.com/data/ExcelExample.xlsx', destfile = 'data/ExcelExample.xlsx').

标签: r excel rcurl downloadfile


【解决方案1】:

这对我有用。

target = "http://www.abs.gov.au/ausstats/meisubs.NSF/log?openagent&5206001_key_aggregates.xls&5206.0&Time%20Series%20Spreadsheet&24FF946FB10A10CDCA258192001DAC4B&0&Jun%202017&06.09.2017&Latest"
dest = 'downloaded_file.xls'

download.file(url = target, destfile = dest, mode='wb')

或者,您可以这样做。

library(readxl)
library(httr)
packageVersion("readxl")
url = "https://www.eia.gov/dnav/pet/hist_xls/W_EPC0_SAX_YCUOK_MBBLw.xls"

GET(url, write_disk(tf <- tempfile(fileext = ".xls")))
df <- read_excel(tf, 2L)
str(df)

【讨论】:

    猜你喜欢
    • 2021-05-19
    • 1970-01-01
    • 1970-01-01
    • 2019-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多