【问题标题】:read_excel() yields an error when trying to load one file尝试加载一个文件时 read_excel() 产生错误
【发布时间】:2019-08-01 07:15:04
【问题描述】:

我正在尝试加载以下.xls 文件。

链接到.xls 文件。 https://ufile.io/5vy4g

我正在使用一个函数(我已经减少了必要性。

product <- c("/saltsnck")

gettables <- function(year, weeks, product){
prod <- read_excel("E:/DIR/prod_saltsnck.xls")
}

Map(gettables, year, weeks, product)

DIR 需要更改为文件下载到的DIR。该文件名为prod_saltsnck.xls

当我尝试加载文件时,出现以下错误:

 Error in read_fun(path = path, sheet_i = sheet, limits = limits, shim = shim,  : 
      Failed to open E:DIR/prod_saltsnck.xls

在线查看时,一些建议指出工作表名称不正确,但该文件与我加载到 R 中的许多其他类似文件相同。唯一的区别是它是不同的产品。

当我直接尝试在函数外部读取文件时,我得到了同样的错误:

prod <- read_excel("E:/DIR/prod_saltsnck.xls")

我似乎无法在 excel 文件中找到问题,之前加载的所有 30 个产品 excel 表都可以正常工作。

编辑:

这是一个有效的 excel 文件,但可能已损坏?我可以毫无问题地使用excel打开excel文件。

编辑 2:

> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=Spanish_Spain.1252  LC_CTYPE=Spanish_Spain.1252    LC_MONETARY=Spanish_Spain.1252
[4] LC_NUMERIC=C                   LC_TIME=Spanish_Spain.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] reshape_0.8.7   bindrcpp_0.2.2  forcats_0.3.0   stringr_1.3.1   purrr_0.2.5     readr_1.1.1    
 [7] tidyr_0.8.1     tibble_1.4.2    ggplot2_3.0.0   tidyverse_1.2.1 plyr_1.8.4      readxl_1.1.0   
[13] dplyr_0.7.6     magrittr_1.5   

【问题讨论】:

  • 是的,该文件存在,我附上了当我尝试使用 R 导入数据集函数加载它时收到的错误的屏幕截图。
  • 你使用哪个包?我猜是readxl?您是否尝试更新软件包?
  • 是的包是`library(readxl)` 我使用的是版本readxl_1.1.0
  • 试试 readr::read_tsv
  • 我收到此错误:&gt; prod &lt;- read_tsv("E:/IRI Data/Academic Dataset External/parsed stub files/prod_saltsnck.xls") Parsed with column specification: cols( ``&lt;d0&gt;&lt;cf&gt;&lt;U+0871&gt;&lt;e1&gt;`` = col_character(), col_character(), A = col_character() ) Error in read_tokens_(data, tokenizer, col_specs, col_names, locale_, : Evaluation error: Column 2 must be named.

标签: r excel


【解决方案1】:

看起来我们正在访问相同的数据集,因为我也遇到了 prod_saltsnck.xls 这个问题,而不是其他产品文件。也许你已经解决了这个问题,但觉得回应可能会有所帮助。您可以将 .xls 文件另存为 .xlsx,然后使用 read_excel 函数读取文件。阅读文件后,您会注意到有几行带有NA 单元格。我怀疑这可能是read_excel 不适用于 .xls 的原因,尽管我没有解释为什么该函数适用于 .xlsx 文件。希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2014-07-28
    • 1970-01-01
    • 2019-12-03
    • 2017-11-09
    • 2011-04-02
    • 1970-01-01
    • 2012-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多