0

I am trying to retrieve an Excel file from the internet, but the link is a download link which automatically downloads the file. I have tried to read this directly into R, but it seems to corrupt the file, and make it unreadable.

I have tried:

  temp <- tempfile()
  download.file("https://animaldrugsatfda.fda.gov/adafda/app/search/public/ingredientsInformationExcel/Section2ActiveIngredients",temp)
  FDAAnimalApprovedDrugs <- readLines(temp)
squishy
  • 489
  • 1
  • 6
  • 19
  • Try `gdata::read.xls(temp)` for example – user20650 Oct 19 '18 at 13:00
  • and/or ... https://stackoverflow.com/questions/6099243/read-an-excel-file-directly-from-a-r-script – user20650 Oct 19 '18 at 13:04
  • If the file is an xls file, you cannot read it with `readLines`. It does not contain text. Can you open the saved file with MS Excel? – G5W Oct 19 '18 at 13:05
  • The temp file? No. I cannot. – squishy Oct 19 '18 at 13:06
  • Just to clarify, if you look at the link, it's not a direct link to the spreadsheet where xls is in the address. Otherwise it would be easy. – squishy Oct 19 '18 at 13:13
  • 1
    @squishy ; this downloaded and read in without problem for me using either `gdata::read.xls(temp)` or `readxl::read_xls(temp)`, and code / link from your question. If you are on Windows perhaps perhaps you need [mode="wb"](https://stackoverflow.com/questions/15250257/r-download-file-issue-with-excel-workbook) – user20650 Oct 19 '18 at 13:14
  • thanks - the mode="wb" worked. – squishy Oct 19 '18 at 13:40

0 Answers0