Search code examples
rreadxl

Don't skip empty leading rows when using readxl


Read_excel() function automatically skips leading empty rows. Is there a way to avoid this as I need the row.names in R to correspond with row numbers in excel?

It is impossible to satisfy this objective when I am unaware how many leading rows were skipped by read_excel.


Solution

  • You can use the range argument of the read_excel function as the documentation for this argument of the function says:

    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.

    Additionally, you might want to set col_names = FALSE, such that the row-numbering stays the same.