Loading Excel spreadsheets
One of the most popular file formats to store and transfer relatively small amounts of data in academic institutions and businesses (besides CSV files) is still Excel xls
(or xlsx
, more recently). The first is a proprietary binary file format from Microsoft, which is exhaustively documented (the xls
specification is available in a document of more than 1,100 pages and 50 megabytes!), but importing multiple sheets, macros, and formulas is not straightforward even nowadays. This section will only cover the most used platform-independent packages to interact with Excel.
One option is to use the previously discussed RODBC
package with the Excel driver to query an Excel spreadsheet. Other ways of accessing Excel data depend on third-party tools, such as using Perl to automatically convert the Excel file to CSV then importing it into R as the read.xls
function from the gdata
package. But installing Perl on Windows sometimes seems to be tedious; thus, RODBC
might be a more convenient method on that platform.
Some platform-independent, Java-based solutions also provide a way to not just read, but also write Excel files, especially to the xlsx
, the Office Open XML file, format. Two separate implementations exist on CRAN to read and write Excel 2007 and the 97/2000/XP/2003 file formats: the xlConnect
and the xlsx
packages. Both are actively maintained, and use the Apache POI Java API project. This latter means that it runs on any platform that supports Java, and there is no need to have Microsoft Excel or Office on the computer; both packages can read and write Excel files on their own.
On the other hand, if you would rather not depend on Perl or Java, the recently published openxlsx
package provides a platform-independent (C++-powered) way of reading and writing xlsx
files. Hadley Wickham released a similar package, but with a slightly modified scope: the readxl
package can read (but not write) both the xls
and xlsx
file formats.
Remember: pick the most appropriate tool for your needs! For example to read Excel files without many external dependencies, I'd choose readxl
; but, for writing Excel 2003 spreadsheets with cell formatting and more advanced features, probably we cannot save the Java dependency and should use the xlConnect
or xlsx
packages over the xlsx
-only
openxlsx
package.