joachim-gassen / tidycovid19

{tidycovid19}: An R Package to Download, Tidy and Visualize Covid-19 Related Data
https://joachim-gassen.github.io/tidycovid19/
Other
146 stars 44 forks source link

Evaluation error when using download_acaps_npi_data() #1

Closed conrad-mac closed 4 years ago

conrad-mac commented 4 years ago

Hi,

First of all, thanks for all your work in standing up this repository.

I am having an issue running download_acaps_npi_data() - I get the following error: Error: Evaluation error: error -103 with zipfile in unzGetCurrentFileInfo. I narrowed it down to

tmp_file <- tempfile(".xlsx")
utils::download.file(paste0("https://data.humdata.org", 
        dta_url), tmp_file, quiet = silent)
raw_dta <- readxl::read_excel(tmp_file, sheet = "Database")

The downloaded excel sheet is corrupted so won't open. I'm on Windows, so I think the issue is that the mode for utils::download.file() needs to be set to "wb" (this doesn't seem to be an issue for Unix-like OS - which I assume you're on). I.e.

tmp_file <- tempfile(".xlsx")
utils::download.file(paste0("https://data.humdata.org", 
        dta_url), tmp_file, quiet = silent, mode = "wb")
raw_dta <- readxl::read_excel(tmp_file, sheet = "Database")

Kind regards

joachim-gassen commented 4 years ago

Thank you and great catch! You are right, download.file does not switch to binary on .xlsx files. I applied your fix. Can you check whether it works for you and then we can close the issue.

conrad-mac commented 4 years ago

No problem. I can confirm this is fixed.

joachim-gassen commented 4 years ago

Great. Thanks again!