Overview

The readxl package makes it easy to get data out of Excel and into R. Compared to many of the existing packages (e.g. gdata, xlsx, xlsReadWrite) readxl has no external dependencies, so it’s easy to install and use on all operating systems. It is designed to work with tabular data.

readxl supports both the legacy .xls format and the modern xml-based .xlsx format. The libxls C library is used to support .xls, which abstracts away many of the complexities of the underlying binary format. To parse .xlsx, we use the RapidXML C++ library.

Installation

The easiest way to install the latest released version from CRAN is to install the whole tidyverse.

If you are new to the tidyverse conventions for data import, you may want to consult the data import chapter in R for Data Science. readxl will become increasingly consistent with other packages, such as readr.

Discovers the minimal data rectangle and returns that, by default. User can exert more control with range, skip, and n_max.

Column names and types are determined from the data in the sheet, by default. User can also supply via col_names and col_types and control name repair via .name_repair.

Returns a tibble, i.e. a data frame with an additional tbl_df class. Among other things, this provide nicer printing.

Other relevant packages

Here are some other packages with functionality that is complementary to readxl and that also avoid a Java dependency.

Writing Excel files: The example files datasets.xlsx and datasets.xls were created with the help of openxlsx (and Excel). openxlsx provides “a high level interface to writing, styling and editing worksheets”.

writexl is a new option in this space, first released on CRAN in August 2017. It’s a portable and lightweight way to export a data frame to xlsx, based on libxlsxwriter. It is much more minimalistic than openxlsx, but on simple examples, appears to be about twice as fast and to write smaller files.

Non-tabular data and formatting: tidyxl is focused on importing awkward and non-tabular data from Excel. It also “exposes cell content, position and formatting in a tidy structure for further manipulation”.

Please note that the readxl project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.