Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read blank excel sheets with headers #144

Closed
zx8754 opened this issue Nov 3, 2015 · 1 comment
Closed

Read blank excel sheets with headers #144

zx8754 opened this issue Nov 3, 2015 · 1 comment

Comments

@zx8754
Copy link

zx8754 commented Nov 3, 2015

I need to read the sheet with headers, even if there is no data.

Example: if we have an excel file temp.xlsx with a sheet named Sheet1 with 3 columns as below with no data rows, just a header:

image

read_excel("temp.xlsx","Sheet1")

Gives error:

Error: Skipped over all data

I could set col_names = FALSE, then use the 1st row to be a header. As I need to read multiple sheets, some will have data and some will be blank with just a header, this is a bit painful.

Any better solution?

sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

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

other attached packages:
[1] readxl_0.1.0 dplyr_0.4.3 

loaded via a namespace (and not attached):
[1] magrittr_1.5   R6_2.1.1       assertthat_0.1 parallel_3.2.2 DBI_0.3.1      tools_3.2.2    Rcpp_0.12.1 
@jennybc
Copy link
Member

jennybc commented Jan 4, 2017

Semi-duplicate of #222. Only difference: this issue confirms same behaviour happens when column headers are present, but there's no data. I verified that.

@jennybc jennybc closed this as completed Jan 4, 2017
jennybc added a commit that referenced this issue Jan 31, 2017
#240)

* Load cells at xlsx worksheet ingest; handle skipping and/or blank rows; fixes #224

* Actually these *should* be the same

* Make skipping tests more challenging (blank row btwn col names and data, plus another embedded blank row)

* Simplify return of 0x0 tibble for completely empty worksheet

* Mark cells to start reading from at the time of worksheet construction

* Remove vestigial, internal cell printing function

* Be quiet about empty worksheet

* More tests of nothingness

* Inform worksheet about its own name

* Tighten up the NEWs bullet for this PR

* Make some accessor member functions const

* Use skip() to issue note-to-future-self

Expedient place to park a summary of what this entire PR does.

* Improved parsing of sheet geometry for xlsx. (#240, @jennybc).

    - Better handling of leading and embedded blank rows and explicit row skipping. (#224, #194, #178, #156, #101)
    - Worksheets that are completely empty or that contain only column names no longer error, but return a tibble with zero rows. (#222, #144, #65)
    - Location is inferred for cells that do not declare their location (e.g. xlsx written by JMP). (#163, #102)
@lock lock bot locked and limited conversation to collaborators Oct 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants