read_excel R中的开单元格范围

时间:2019-01-27 14:34:43

标签: r excel

是否可以在R的read_excel函数中不指定单元格范围?

例如,如果数据条目开始于单元格C3并结束于单元格D300,是否可以不强制我指定D300,而是让R读取直到不再有包含数据条目的单元格?< / p>

类似的东西:

A <- read_excel("excell/book.xlsx", sheet="A", range="C3:")

1 个答案:

答案 0 :(得分:1)

如果您阅读readxl::read_excel的文档,则其中包含

range: A cell range to read from, as described in
       cell-specification. Includes typical Excel ranges like
       "B3:D87", possibly including the sheet name like
       "Budget!B2:G14", and more. Interpreted strictly, even if the
       range forces the inclusion of leading or trailing empty rows
       or columns. Takes precedence over 'skip', 'n_max' and
       'sheet'.

尽管很容易假设它必须是字符串,但是如果您深入研究?readxl::cell-specification,则建议您研究cellranger::cell_limits()。就是说

cell_limits(ul = c(NA_integer_, NA_integer_), lr = c(NA_integer_,
  NA_integer_), sheet = NA_character_)
...
A value of 'NA' in 'ul' or 'lr' means the corresponding limit is left unspecified.

这表示您可以使用NA保持打开状态。

尝试:

A <- read_excel("excell/book.xlsx", sheet="A", range=cellranger::cell_limits(c(3,3)))

未指定的lr将右下角保持打开状态。