【问题标题】:Permission Denied Error when downloading a file下载文件时权限被拒绝错误
【发布时间】:2022-01-25 21:11:32
【问题描述】:

我正在尝试将 excel zip 文件下载到我已启动的 R 项目文件夹中。我是 R 新手,所以我对收到的错误消息有点困惑。

该文件是一个 excel 文件,所以我首先为该文件创建了一个变量:

excel2file="http://op.nsf.data/dataFiles/Housing2013EXCEL.zip"

然后我使用了编码:

download.file(excel2file, destfile= "~/Home/Documents/Data")

我收到此错误消息:

Error in download.file(excel2file, destfile = "~/Home/Documents/Data") : 
  cannot open destfile '~/Home/Documents/Data', reason 'Permission denied'

我尝试查看其他权限被拒绝的示例,我认为这可能是我的目标文件,但我不确定原因或解决问题的步骤。

【问题讨论】:

    标签: r


    【解决方案1】:

    destfile 应该是文件名,而不是目录。例如:

    download.file(excel2file, destfile= "~/Home/Documents/Data/Housing2013EXCEL.zip")
    

    此外,该 URL 似乎无效,但这是一个不同的(非 R)问题。

    【讨论】:

      【解决方案2】:

      确保您没有在destfile 中打开文件,因为Permission denied 错误也来自无法覆盖打开的文件。

      这让我绊倒了一段时间。

      【讨论】:

        【解决方案3】:

        您可以使用包readr 及其函数read_csv。它允许您下载文件,但它必须是下载的文件,例如 CSV 文件,这样的东西对我有用

        library(readr)
        
        newz <- read_csv("https://www.stats.govt.nz/assets/Uploads/Annual-enterprise-survey/Annual-enterprise-survey-2020-financial-year-provisional/Download-data/annual-enterprise-survey-2020-financial-year-provisional-csv.csv")
        
        View(newz)
        

        关于“权限被拒绝”我仍然没有解决这个问题

        【讨论】:

          【解决方案4】:

          在 destfile 中添加一个名称,例如 /downloadedfile.csv"

          【讨论】:

          • 这已经是公认的答案所解释的内容了。
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-07-19
          相关资源
          最近更新 更多