【问题标题】:R download.File error cannot open URlR下载。文件错误无法打开URl
【发布时间】:2015-01-03 11:19:12
【问题描述】:
temp <- tempfile()
download.file("file://connect/me/test.gz",temp)

该网址存在是因为我可以将它放在我的浏览器中,但是当我运行该代码时出现错误:

  Error in download.file("file://connect/me/test.gz",  : 
    cannot open URL "file://connect/me/test.gz", reason 'No such file or directory'

有什么办法可以下载文件并解压缩吗?

更新

我在这里找到了一些关于 fil:// 的信息 https://stat.ethz.ch/R-manual/R-devel/library/base/html/connections.html:

"关于 file:// URLs 的注释。最通用的形式(来自 RFC1738)是 file://host/path/to/file,但 R 只接受带有空主机字段的形式,指的是本地机器。”

"在这种形式中,路径是相对于文件系统的根目录,而不是 Windows 的概念。Windows 上的标准形式是 file:///d:/R/repos:为了与早期版本的 R 和 Unix 兼容版本中,任何其他形式都被解析为 R 作为 file:// 加上 path_to_file。此外,即使 RFC1738 不允许反斜杠,也可以在路径中使用它们。"

这是什么意思?

ty

【问题讨论】:

  • 也许添加额外的/?类似download.file("file://connect//me//test.gz",temp)
  • @David - 我试过了,得到了同样的错误。你认为这是因为地址以“file”而不是“www”开头
  • @David 你知道更新意味着什么吗?
  • 好像是需要从URL中去掉host
  • 哈哈,是的,这意味着 url 应该是什么样子?我认为为什么下面的人说对空主机使用 /// 3 个斜杠,但这似乎不起作用

标签: r


【解决方案1】:

我想通了。我必须将驱动器“B”映射到文件夹,然后

temp <- tempfile()
download.file("file:///B:/me/test.gz",temp,method="internal")

【讨论】:

    【解决方案2】:

    我认为您需要在 file: 后面加上三个斜杠:其余的一个斜杠。我在 Windows 7 上试过,效果很好。

        temp <- tempfile()
        download.file("file:///C:/Users/Philip/Desktop/Coursera/data/cameras.csv",temp)
    

    【讨论】:

    • 我的看法,@user3022875:当您看到非文件 URL 时,您会看到类似 http://some.host.com/path/to/filename 的内容。 R 不支持带有远程主机的file: URI,因此主机字段需要为空。那么什么是file://remote.host.com/path/to/file 在技术上合法的URI 需要删除远程主机名(但不是周围的斜杠),留下file:///path/to/file。注意三个斜线。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-21
    • 1970-01-01
    • 2015-09-20
    • 2015-07-31
    相关资源
    最近更新 更多